답안 #767596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
767596 2023-06-26T22:24:40 Z rainboy 결혼 문제 (IZhO14_marriage) C
66 / 100
585 ms 9244 KB
/* https://oj.uz/submission/100855 (Benq) */
#include <stdio.h>
#include <string.h>

#define NU	30000
#define NV	2000

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 0 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 0 ms 212 KB Output is correct
7 Incorrect 0 ms 340 KB Output isn't correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Incorrect 0 ms 340 KB Output isn't correct
15 Incorrect 0 ms 340 KB Output isn't correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 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 1 ms 468 KB Output is correct
25 Incorrect 2 ms 724 KB Output isn't correct
26 Incorrect 1 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 692 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Incorrect 10 ms 2604 KB Output isn't correct
32 Incorrect 3 ms 2388 KB Output isn't correct
33 Correct 2 ms 1620 KB Output is correct
34 Correct 6 ms 2388 KB Output is correct
35 Correct 38 ms 2840 KB Output is correct
36 Correct 29 ms 2696 KB Output is correct
37 Incorrect 14 ms 4708 KB Output isn't correct
38 Correct 18 ms 4820 KB Output is correct
39 Correct 231 ms 8928 KB Output is correct
40 Correct 144 ms 8660 KB Output is correct
41 Incorrect 167 ms 8788 KB Output isn't correct
42 Correct 37 ms 4656 KB Output is correct
43 Correct 40 ms 4692 KB Output is correct
44 Correct 97 ms 9072 KB Output is correct
45 Incorrect 466 ms 8916 KB Output isn't correct
46 Incorrect 449 ms 9152 KB Output isn't correct
47 Correct 187 ms 9244 KB Output is correct
48 Correct 185 ms 9112 KB Output is correct
49 Incorrect 451 ms 9172 KB Output isn't correct
50 Correct 585 ms 9060 KB Output is correct