QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#629097 | #4504. Book Club | jdelaure | WA | 0ms | 1600kb | C11 | 3.1kb | 2024-10-11 03:48:26 | 2024-10-11 03:48:26 |
Judging History
answer
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
uint16_t graphAsArray[20002][20002];
//uint16_t graphAsGraph[20002][20002];
uint16_t graphNbEdges[20002];
uint16_t path[20002];
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);
}
}
}
}
*/
uint16_t getEdgeIndex(uint16_t src, uint16_t dst) {
for (uint16_t i = 0; i < graphNbEdges[src]; i++) {
if (graphAsArray[src][i] == dst) {
return i;
}
}
return (uint16_t)-1;
}
void addEdge(uint16_t src, uint16_t dst) {
if (getEdgeIndex(src, dst) == (uint16_t)-1) return;
//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]) {
index = getEdgeIndex(src, dst); //graphAsGraph[src][dst] - 1;
if (index == (uint16_t)-1) return;
replace = --graphNbEdges[src];
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("J.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: 0
Wrong Answer
time: 0ms
memory: 1600kb
input:
5 5 0 1 1 2 2 3 3 4 4 0
output:
NO
result:
wrong answer 1st lines differ - expected: 'YES', found: 'NO'