/* https://oj.uz/submission/100855 (Benq) */
#include <stdio.h>
#include <string.h>
#define NU 30000
#define NV 4000
int nu, nv;
int eu[NV][NU], eo[NV], el[NV], er[NV];
int uu[NV], vv[NU]; char visited[NV];
int dfs(int v) {
int o;
if (visited[v])
return 0;
visited[v] = 1;
for (o = el[v]; o < er[v]; o++) {
int u = eu[v][o], w = vv[u];
if (w == -1 || dfs(w)) {
uu[v] = u, vv[u] = v;
return 1;
}
}
return 0;
}
int check() {
int v;
for (v = 0; v < nv; v++)
if (uu[v] == -1) {
memset(visited, 0, nv * sizeof *visited);
if (!dfs(v))
return 0;
}
return 1;
}
int main() {
int m, h, l, r, u, v, ans;
scanf("%d%d%d", &nu, &nv, &m);
for (h = 0; h < m; h++) {
scanf("%d%d", &u, &v), u--, v--;
eu[v][eo[v]++] = u;
}
memset(uu, -1, nv * sizeof *uu), memset(vv, -1, nu * sizeof *vv);
ans = 0;
for (l = 0, r = -1; l < nu; l++) {
while (r < nu && !check()) {
r++;
for (v = 0; v < nv; v++)
if (er[v] < eo[v] && eu[v][er[v]] == r)
er[v]++;
}
ans += nu - r;
for (v = 0; v < nv; v++) {
if (el[v] < eo[v] && eu[v][el[v]] == l)
el[v]++;
if (uu[v] == l)
uu[v] = -1;
}
}
printf("%d\n", ans);
return 0;
}
Compilation message
marriage.c: In function 'main':
marriage.c:44:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d%d%d", &nu, &nv, &m);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
marriage.c:46:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d%d", &u, &v), u--, v--;
| ^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
20 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
21 |
Correct |
0 ms |
468 KB |
Output is correct |
22 |
Correct |
0 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
0 ms |
468 KB |
Output is correct |
25 |
Incorrect |
3 ms |
724 KB |
Output isn't correct |
26 |
Incorrect |
2 ms |
724 KB |
Output isn't correct |
27 |
Correct |
1 ms |
724 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
724 KB |
Output is correct |
30 |
Correct |
2 ms |
644 KB |
Output is correct |
31 |
Incorrect |
8 ms |
2520 KB |
Output isn't correct |
32 |
Incorrect |
3 ms |
2392 KB |
Output isn't correct |
33 |
Correct |
2 ms |
1624 KB |
Output is correct |
34 |
Correct |
6 ms |
2388 KB |
Output is correct |
35 |
Correct |
49 ms |
2788 KB |
Output is correct |
36 |
Correct |
50 ms |
2704 KB |
Output is correct |
37 |
Incorrect |
14 ms |
4720 KB |
Output isn't correct |
38 |
Correct |
19 ms |
4948 KB |
Output is correct |
39 |
Correct |
255 ms |
8956 KB |
Output is correct |
40 |
Correct |
173 ms |
8760 KB |
Output is correct |
41 |
Incorrect |
160 ms |
8812 KB |
Output isn't correct |
42 |
Correct |
55 ms |
4648 KB |
Output is correct |
43 |
Correct |
40 ms |
4784 KB |
Output is correct |
44 |
Correct |
167 ms |
9056 KB |
Output is correct |
45 |
Incorrect |
466 ms |
8920 KB |
Output isn't correct |
46 |
Incorrect |
484 ms |
9148 KB |
Output isn't correct |
47 |
Correct |
213 ms |
9256 KB |
Output is correct |
48 |
Correct |
188 ms |
9116 KB |
Output is correct |
49 |
Incorrect |
573 ms |
9220 KB |
Output isn't correct |
50 |
Correct |
769 ms |
9028 KB |
Output is correct |