QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#629075 | #4504. Book Club | jdelaure | RE | 1ms | 3612kb | C11 | 2.7kb | 2024-10-11 02:58:42 | 2024-10-11 02:58:44 |
Judging History
answer
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
uint16_t graphAsArray[20004][20004];
uint8_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");
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3612kb
input:
5 5 0 1 1 2 2 3 3 4 4 0
output:
YES
result:
ok single line: 'YES'
Test #2:
score: -100
Runtime Error
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...