QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#629084 | #4504. Book Club | jdelaure | ML | 43ms | 494380kb | C11 | 2.7kb | 2024-10-11 03:16:18 | 2024-10-11 03:16:19 |
Judging History
answer
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
uint16_t graphAsArray[20004][20004];
uint16_t graphAsGraph[20004][20004];
uint16_t graphNbEdges[20004];
uint16_t path[20004];
int nbPeople;
void sanityCheck() {
for (int src = 0; src <= nbPeople*2+1; src++) {
for (int i = 0; i < graphNbEdges[src]; i++) {
int dst = graphAsArray[src][i];
if (!graphAsGraph[src][dst]) {
fprintf(stderr, "what the fuck %d %d\n", src, dst);
printf("[%i][%i]\n", src, i);
}
}
}
}
void addEdge(uint16_t src, uint16_t dst) {
if (!graphAsGraph[src][dst]) {
int index = graphNbEdges[src]++;
graphAsGraph[src][dst] = index + 1;
graphAsArray[src][index] = dst;
}
//sanityCheck();
}
void removeEdge(uint16_t src, uint16_t dst) {
int index, replace;
uint16_t newDst;
if (graphAsGraph[src][dst]) {
replace = --graphNbEdges[src];
index = graphAsGraph[src][dst] - 1;
newDst = graphAsArray[src][replace];
graphAsGraph[src][dst] = 0;
graphAsArray[src][index] = newDst;
graphAsGraph[src][newDst] = index + 1;
}
//sanityCheck();
}
bool searchPath(uint16_t source, uint16_t target) {
if (source == target)
return true;
for (int i = 0; i < graphNbEdges[source]; i++) {
uint16_t dst = graphAsArray[source][i];
if (path[dst] == (uint16_t)-1) {
path[dst] = source;
if (searchPath(dst, target))
return true;
}
}
return false;
}
int fordFulkerson(uint16_t source, uint16_t target) {
uint16_t u, v;
int maxFlow = 0;
for (;;) {
memset(path, -1, sizeof(path));
if (!searchPath(source, target))
break;
//printf("%i %i\n", source, target);
v = target;
while (v != source) {
u = path[v];
removeEdge(u, v);
addEdge(v, u);
v = path[v];
}
maxFlow++;
}
return maxFlow;
}
int main(void) {
//freopen("J2.in", "r", stdin);
int nbDeclarations;
int person, preference;
scanf("%d %d", &nbPeople, &nbDeclarations);
for (int i = 0; i < nbDeclarations; i++) {
scanf("%d %d", &person, &preference);
addEdge(person*2, preference*2+1);
}
for (int i = 0; i < nbPeople; i++) {
addEdge(nbPeople*2, i*2);
addEdge(i*2+1, nbPeople*2+1);
}
int result = fordFulkerson(nbPeople*2, nbPeople*2+1);
if (result == nbPeople) {
printf("YES\n");
} else {
printf("NO\n");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3744kb
input:
5 5 0 1 1 2 2 3 3 4 4 0
output:
YES
result:
ok single line: 'YES'
Test #2:
score: 0
Accepted
time: 7ms
memory: 97148kb
input:
1000 5000 0 271 0 320 0 325 0 378 0 562 0 942 0 957 1 88 1 235 1 271 1 579 1 604 1 751 1 875 1 929 2 70 2 403 2 470 2 909 2 912 3 352 3 657 3 810 4 201 4 361 4 414 4 418 4 505 4 531 4 597 4 833 5 14 5 123 5 281 5 878 5 938 6 311 6 392 6 564 6 994 7 246 7 353 7 372 7 710 7 751 7 772 8 149 8 435 8 682...
output:
NO
result:
ok single line: 'NO'
Test #3:
score: 0
Accepted
time: 27ms
memory: 384180kb
input:
10000 10000 0 3378 1 8751 2 9999 3 7769 4 6001 5 9998 6 9311 7 9996 8 7722 9 1572 10 9994 11 3865 12 186 13 7614 14 9992 15 9991 16 4424 17 9807 18 5031 19 7909 20 4994 21 292 22 9990 23 8180 24 5837 25 9989 26 9554 27 7552 28 8027 29 5135 30 9988 31 4067 32 702 33 9984 34 8831 35 6971 36 7354 37 81...
output:
YES
result:
ok single line: 'YES'
Test #4:
score: 0
Accepted
time: 20ms
memory: 413584kb
input:
10000 10000 0 3378 1 8751 2 9999 3 7769 4 6001 5 9998 6 9311 7 9996 8 7722 9 1572 10 9994 11 3865 12 186 13 7614 14 9992 15 9991 16 4424 17 9807 18 5031 19 7909 20 4994 21 292 22 9990 23 8180 24 5837 25 9989 26 9554 27 7552 28 8027 29 5135 30 9988 31 4067 32 702 33 9984 34 8831 35 6971 36 7354 37 81...
output:
NO
result:
ok single line: 'NO'
Test #5:
score: 0
Accepted
time: 43ms
memory: 494380kb
input:
10000 20000 0 3378 0 6398 1 3271 1 6775 1 8751 2 9999 3 7769 4 1201 4 6001 4 6908 5 9997 6 9311 7 9995 8 2240 8 7722 9 1572 10 9994 11 3865 12 186 12 6999 12 8543 13 6075 13 6124 13 7614 13 8433 14 9986 15 3587 16 1761 16 3977 16 4424 16 5036 16 8714 16 9441 17 2109 17 9807 18 3502 18 5031 19 7909 2...
output:
NO
result:
ok single line: 'NO'
Test #6:
score: -100
Memory Limit Exceeded
input:
10000 20000 0 3378 0 6398 1 3271 1 6775 1 8751 2 9999 3 7769 4 1201 4 6001 4 6908 5 9997 6 9311 7 9995 8 2240 8 7722 9 1572 10 9994 11 3865 12 186 12 6999 12 8543 13 6075 13 6124 13 7614 13 8433 14 9986 15 3587 16 1761 16 3977 16 4424 16 5036 16 8714 16 9441 17 2109 17 9807 18 3502 18 5031 19 7909 2...
output:
NO