Submission #158730

# Submission time Handle Problem Language Result Execution time Memory
158730 2019-10-18T14:18:35 Z maruii None (KOI18_family) C++14
100 / 100
335 ms 47236 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define ff first
#define ss second

int N, M, K;
struct G {
	vector<int> edge[300005];
	int sz[300005], rep[300005];
	void dfs(int x) {
		if (x && x <= K) rep[x] = x, sz[x] = 1;
		for (auto i : edge[x]) {
			dfs(i);
			rep[x] = rep[i];
			sz[x] += sz[i];
		}
	}
} t1, t2;

int par[300005], sz[300005];
int fnd(int x) { return x == par[x] ? x : par[x] = fnd(par[x]); }
void uni(int x, int y) {
	x = fnd(x), y = fnd(y);
	if (x == y) return;
	par[y] = x;
	sz[x] += sz[y];
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> N >> M >> K;
	iota(par, par + K + 1, 0);
	fill(sz, sz + K + 1, 1);
	for (int i = 1; i <= N; ++i) {
		int x; cin >> x;
		t1.edge[x].push_back(i);
	}
	for (int i = 1; i <= M; ++i) {
		int x; cin >> x;
		t2.edge[x].push_back(i);
	}
	t1.dfs(0);
	t2.dfs(0);
	vector<pii> vec;
	for (int i = K + 1; i <= N; ++i) if (t1.edge[i].size() > 1) vec.emplace_back(t1.sz[i], i);
	for (int i = K + 1; i <= M; ++i) if (t2.edge[i].size() > 1) vec.emplace_back(t2.sz[i], -i);
	sort(vec.begin(), vec.end());
	for (auto i : vec) {
		int r;
		if (i.ss < 0) {
			i.ss = -i.ss;
			r = t2.rep[i.ss];
			for (auto j : t2.edge[i.ss]) uni(r, t2.rep[j]);
		}
		else {
			r = t1.rep[i.ss];
			for (auto j : t1.edge[i.ss]) uni(r, t1.rep[j]);
		}
		if (sz[fnd(r)] != i.ff) return !printf("NO");
	}
	printf("YES");
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14460 KB Output is correct
4 Correct 14 ms 14452 KB Output is correct
5 Correct 15 ms 14460 KB Output is correct
6 Correct 15 ms 14456 KB Output is correct
7 Correct 14 ms 14456 KB Output is correct
8 Correct 14 ms 14456 KB Output is correct
9 Correct 14 ms 14456 KB Output is correct
10 Correct 14 ms 14456 KB Output is correct
11 Correct 14 ms 14456 KB Output is correct
12 Correct 15 ms 14468 KB Output is correct
13 Correct 14 ms 14428 KB Output is correct
14 Correct 14 ms 14456 KB Output is correct
15 Correct 14 ms 14456 KB Output is correct
16 Correct 15 ms 14712 KB Output is correct
17 Correct 14 ms 14456 KB Output is correct
18 Correct 14 ms 14456 KB Output is correct
19 Correct 15 ms 14460 KB Output is correct
20 Correct 14 ms 14460 KB Output is correct
21 Correct 15 ms 14456 KB Output is correct
22 Correct 14 ms 14456 KB Output is correct
23 Correct 14 ms 14456 KB Output is correct
24 Correct 15 ms 14456 KB Output is correct
25 Correct 14 ms 14456 KB Output is correct
26 Correct 14 ms 14456 KB Output is correct
27 Correct 14 ms 14448 KB Output is correct
28 Correct 14 ms 14456 KB Output is correct
29 Correct 14 ms 14456 KB Output is correct
30 Correct 14 ms 14456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14460 KB Output is correct
4 Correct 14 ms 14452 KB Output is correct
5 Correct 15 ms 14460 KB Output is correct
6 Correct 15 ms 14456 KB Output is correct
7 Correct 14 ms 14456 KB Output is correct
8 Correct 14 ms 14456 KB Output is correct
9 Correct 14 ms 14456 KB Output is correct
10 Correct 14 ms 14456 KB Output is correct
11 Correct 14 ms 14456 KB Output is correct
12 Correct 15 ms 14468 KB Output is correct
13 Correct 14 ms 14428 KB Output is correct
14 Correct 14 ms 14456 KB Output is correct
15 Correct 14 ms 14456 KB Output is correct
16 Correct 15 ms 14712 KB Output is correct
17 Correct 14 ms 14456 KB Output is correct
18 Correct 14 ms 14456 KB Output is correct
19 Correct 15 ms 14460 KB Output is correct
20 Correct 14 ms 14460 KB Output is correct
21 Correct 15 ms 14456 KB Output is correct
22 Correct 14 ms 14456 KB Output is correct
23 Correct 14 ms 14456 KB Output is correct
24 Correct 15 ms 14456 KB Output is correct
25 Correct 14 ms 14456 KB Output is correct
26 Correct 14 ms 14456 KB Output is correct
27 Correct 14 ms 14448 KB Output is correct
28 Correct 14 ms 14456 KB Output is correct
29 Correct 14 ms 14456 KB Output is correct
30 Correct 14 ms 14456 KB Output is correct
31 Correct 14 ms 14456 KB Output is correct
32 Correct 14 ms 14456 KB Output is correct
33 Correct 14 ms 14456 KB Output is correct
34 Correct 14 ms 14460 KB Output is correct
35 Correct 14 ms 14456 KB Output is correct
36 Correct 14 ms 14456 KB Output is correct
37 Correct 15 ms 14456 KB Output is correct
38 Correct 15 ms 14456 KB Output is correct
39 Correct 15 ms 14712 KB Output is correct
40 Correct 15 ms 14460 KB Output is correct
41 Correct 15 ms 14456 KB Output is correct
42 Correct 14 ms 14456 KB Output is correct
43 Correct 14 ms 14456 KB Output is correct
44 Correct 14 ms 14456 KB Output is correct
45 Correct 15 ms 14456 KB Output is correct
46 Correct 14 ms 14456 KB Output is correct
47 Correct 14 ms 14456 KB Output is correct
48 Correct 15 ms 14456 KB Output is correct
49 Correct 14 ms 14456 KB Output is correct
50 Correct 14 ms 14492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14460 KB Output is correct
4 Correct 14 ms 14452 KB Output is correct
5 Correct 15 ms 14460 KB Output is correct
6 Correct 15 ms 14456 KB Output is correct
7 Correct 14 ms 14456 KB Output is correct
8 Correct 14 ms 14456 KB Output is correct
9 Correct 14 ms 14456 KB Output is correct
10 Correct 14 ms 14456 KB Output is correct
11 Correct 14 ms 14456 KB Output is correct
12 Correct 15 ms 14468 KB Output is correct
13 Correct 14 ms 14428 KB Output is correct
14 Correct 14 ms 14456 KB Output is correct
15 Correct 14 ms 14456 KB Output is correct
16 Correct 15 ms 14712 KB Output is correct
17 Correct 14 ms 14456 KB Output is correct
18 Correct 14 ms 14456 KB Output is correct
19 Correct 15 ms 14460 KB Output is correct
20 Correct 14 ms 14460 KB Output is correct
21 Correct 15 ms 14456 KB Output is correct
22 Correct 14 ms 14456 KB Output is correct
23 Correct 14 ms 14456 KB Output is correct
24 Correct 15 ms 14456 KB Output is correct
25 Correct 14 ms 14456 KB Output is correct
26 Correct 14 ms 14456 KB Output is correct
27 Correct 14 ms 14448 KB Output is correct
28 Correct 14 ms 14456 KB Output is correct
29 Correct 14 ms 14456 KB Output is correct
30 Correct 14 ms 14456 KB Output is correct
31 Correct 14 ms 14456 KB Output is correct
32 Correct 14 ms 14456 KB Output is correct
33 Correct 14 ms 14456 KB Output is correct
34 Correct 14 ms 14460 KB Output is correct
35 Correct 14 ms 14456 KB Output is correct
36 Correct 14 ms 14456 KB Output is correct
37 Correct 15 ms 14456 KB Output is correct
38 Correct 15 ms 14456 KB Output is correct
39 Correct 15 ms 14712 KB Output is correct
40 Correct 15 ms 14460 KB Output is correct
41 Correct 15 ms 14456 KB Output is correct
42 Correct 14 ms 14456 KB Output is correct
43 Correct 14 ms 14456 KB Output is correct
44 Correct 14 ms 14456 KB Output is correct
45 Correct 15 ms 14456 KB Output is correct
46 Correct 14 ms 14456 KB Output is correct
47 Correct 14 ms 14456 KB Output is correct
48 Correct 15 ms 14456 KB Output is correct
49 Correct 14 ms 14456 KB Output is correct
50 Correct 14 ms 14492 KB Output is correct
51 Correct 16 ms 14712 KB Output is correct
52 Correct 17 ms 14712 KB Output is correct
53 Correct 17 ms 14840 KB Output is correct
54 Correct 17 ms 14652 KB Output is correct
55 Correct 16 ms 14712 KB Output is correct
56 Correct 16 ms 14716 KB Output is correct
57 Correct 17 ms 14712 KB Output is correct
58 Correct 16 ms 14712 KB Output is correct
59 Correct 16 ms 14712 KB Output is correct
60 Correct 16 ms 14712 KB Output is correct
61 Correct 17 ms 14968 KB Output is correct
62 Correct 17 ms 14892 KB Output is correct
63 Correct 16 ms 14712 KB Output is correct
64 Correct 16 ms 14712 KB Output is correct
65 Correct 15 ms 14456 KB Output is correct
66 Correct 17 ms 14840 KB Output is correct
67 Correct 16 ms 14712 KB Output is correct
68 Correct 16 ms 14712 KB Output is correct
69 Correct 17 ms 14840 KB Output is correct
70 Correct 15 ms 14712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14460 KB Output is correct
4 Correct 14 ms 14452 KB Output is correct
5 Correct 15 ms 14460 KB Output is correct
6 Correct 15 ms 14456 KB Output is correct
7 Correct 14 ms 14456 KB Output is correct
8 Correct 14 ms 14456 KB Output is correct
9 Correct 14 ms 14456 KB Output is correct
10 Correct 14 ms 14456 KB Output is correct
11 Correct 14 ms 14456 KB Output is correct
12 Correct 15 ms 14468 KB Output is correct
13 Correct 14 ms 14428 KB Output is correct
14 Correct 14 ms 14456 KB Output is correct
15 Correct 14 ms 14456 KB Output is correct
16 Correct 15 ms 14712 KB Output is correct
17 Correct 14 ms 14456 KB Output is correct
18 Correct 14 ms 14456 KB Output is correct
19 Correct 15 ms 14460 KB Output is correct
20 Correct 14 ms 14460 KB Output is correct
21 Correct 15 ms 14456 KB Output is correct
22 Correct 14 ms 14456 KB Output is correct
23 Correct 14 ms 14456 KB Output is correct
24 Correct 15 ms 14456 KB Output is correct
25 Correct 14 ms 14456 KB Output is correct
26 Correct 14 ms 14456 KB Output is correct
27 Correct 14 ms 14448 KB Output is correct
28 Correct 14 ms 14456 KB Output is correct
29 Correct 14 ms 14456 KB Output is correct
30 Correct 14 ms 14456 KB Output is correct
31 Correct 14 ms 14456 KB Output is correct
32 Correct 14 ms 14456 KB Output is correct
33 Correct 14 ms 14456 KB Output is correct
34 Correct 14 ms 14460 KB Output is correct
35 Correct 14 ms 14456 KB Output is correct
36 Correct 14 ms 14456 KB Output is correct
37 Correct 15 ms 14456 KB Output is correct
38 Correct 15 ms 14456 KB Output is correct
39 Correct 15 ms 14712 KB Output is correct
40 Correct 15 ms 14460 KB Output is correct
41 Correct 15 ms 14456 KB Output is correct
42 Correct 14 ms 14456 KB Output is correct
43 Correct 14 ms 14456 KB Output is correct
44 Correct 14 ms 14456 KB Output is correct
45 Correct 15 ms 14456 KB Output is correct
46 Correct 14 ms 14456 KB Output is correct
47 Correct 14 ms 14456 KB Output is correct
48 Correct 15 ms 14456 KB Output is correct
49 Correct 14 ms 14456 KB Output is correct
50 Correct 14 ms 14492 KB Output is correct
51 Correct 16 ms 14712 KB Output is correct
52 Correct 17 ms 14712 KB Output is correct
53 Correct 17 ms 14840 KB Output is correct
54 Correct 17 ms 14652 KB Output is correct
55 Correct 16 ms 14712 KB Output is correct
56 Correct 16 ms 14716 KB Output is correct
57 Correct 17 ms 14712 KB Output is correct
58 Correct 16 ms 14712 KB Output is correct
59 Correct 16 ms 14712 KB Output is correct
60 Correct 16 ms 14712 KB Output is correct
61 Correct 17 ms 14968 KB Output is correct
62 Correct 17 ms 14892 KB Output is correct
63 Correct 16 ms 14712 KB Output is correct
64 Correct 16 ms 14712 KB Output is correct
65 Correct 15 ms 14456 KB Output is correct
66 Correct 17 ms 14840 KB Output is correct
67 Correct 16 ms 14712 KB Output is correct
68 Correct 16 ms 14712 KB Output is correct
69 Correct 17 ms 14840 KB Output is correct
70 Correct 15 ms 14712 KB Output is correct
71 Correct 43 ms 18424 KB Output is correct
72 Correct 48 ms 17836 KB Output is correct
73 Correct 32 ms 16996 KB Output is correct
74 Correct 48 ms 19608 KB Output is correct
75 Correct 45 ms 19320 KB Output is correct
76 Correct 315 ms 47236 KB Output is correct
77 Correct 335 ms 42360 KB Output is correct
78 Correct 238 ms 30832 KB Output is correct
79 Correct 276 ms 40824 KB Output is correct
80 Correct 317 ms 39672 KB Output is correct
81 Correct 46 ms 18296 KB Output is correct
82 Correct 45 ms 17828 KB Output is correct
83 Correct 31 ms 17016 KB Output is correct
84 Correct 44 ms 19576 KB Output is correct
85 Correct 44 ms 19320 KB Output is correct
86 Correct 261 ms 42728 KB Output is correct
87 Correct 286 ms 42952 KB Output is correct
88 Correct 189 ms 30824 KB Output is correct
89 Correct 286 ms 40364 KB Output is correct
90 Correct 297 ms 39772 KB Output is correct