# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
333504 | 2020-12-06T14:21:19 Z | leinad2 | None (KOI18_family) | C++17 | 437 ms | 50028 KB |
#include<bits/stdc++.h> using namespace std; int k, par[300010], i, j, a, s[300010]; vector<pair<int, int> >v; struct tree { int n, leaf[300010], sz[300010]; vector<int>adj[300010]; void dfs(int v) { if(v&&v<=k) { sz[v]=1; leaf[v]=v; return; } for(int x=0;x<adj[v].size();x++) { dfs(adj[v][x]); leaf[v]=leaf[adj[v][x]]; sz[v]+=sz[adj[v][x]]; } } }t1, t2; int Find(int x) { if(x==par[x])return x; return par[x]=Find(par[x]); } void Union(int a, int b) { a=Find(a); b=Find(b); if(a!=b) { s[a]+=s[b]; s[b]=0; par[b]=a; } } int main() { scanf("%d %d %d", &t1.n, &t2.n, &k); for(i=0;i++<k;)par[i]=i,s[i]=1; for(i=0;i++<t1.n;) { scanf("%d", &a); t1.adj[a].push_back(i); } for(i=0;i++<t2.n;) { scanf("%d", &a); t2.adj[a].push_back(i); } t1.dfs(0); t2.dfs(0); for(i=0;i++<t1.n;) { if(t1.adj[i].size()>1)v.push_back({t1.sz[i], i}); } for(i=0;i++<t2.n;) { if(t2.adj[i].size()>1)v.push_back({t2.sz[i], i+t1.n}); } sort(v.begin(), v.end()); for(pair<int, int>i:v) { if(i.second>t1.n) { i.second-=t1.n; a=t2.leaf[i.second]; for(int j:t2.adj[i.second]) { Union(t2.leaf[j], a); } } else { a=t1.leaf[i.second]; for(int j:t1.adj[i.second]) { Union(t1.leaf[j], a); } } if(s[Find(a)]!=i.first) { puts("NO"); return 0; } } puts("YES"); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 14444 KB | Output is correct |
2 | Correct | 10 ms | 14444 KB | Output is correct |
3 | Correct | 10 ms | 14444 KB | Output is correct |
4 | Correct | 10 ms | 14444 KB | Output is correct |
5 | Correct | 10 ms | 14444 KB | Output is correct |
6 | Correct | 10 ms | 14444 KB | Output is correct |
7 | Correct | 10 ms | 14444 KB | Output is correct |
8 | Correct | 11 ms | 14444 KB | Output is correct |
9 | Correct | 10 ms | 14444 KB | Output is correct |
10 | Correct | 10 ms | 14444 KB | Output is correct |
11 | Correct | 10 ms | 14444 KB | Output is correct |
12 | Correct | 12 ms | 14444 KB | Output is correct |
13 | Correct | 10 ms | 14444 KB | Output is correct |
14 | Correct | 10 ms | 14444 KB | Output is correct |
15 | Correct | 10 ms | 14444 KB | Output is correct |
16 | Correct | 10 ms | 14444 KB | Output is correct |
17 | Correct | 10 ms | 14444 KB | Output is correct |
18 | Correct | 10 ms | 14444 KB | Output is correct |
19 | Correct | 10 ms | 14444 KB | Output is correct |
20 | Correct | 10 ms | 14444 KB | Output is correct |
21 | Correct | 10 ms | 14444 KB | Output is correct |
22 | Correct | 10 ms | 14572 KB | Output is correct |
23 | Correct | 10 ms | 14444 KB | Output is correct |
24 | Correct | 10 ms | 14444 KB | Output is correct |
25 | Correct | 10 ms | 14444 KB | Output is correct |
26 | Correct | 12 ms | 14444 KB | Output is correct |
27 | Correct | 13 ms | 14444 KB | Output is correct |
28 | Correct | 11 ms | 14464 KB | Output is correct |
29 | Correct | 10 ms | 14444 KB | Output is correct |
30 | Correct | 10 ms | 14444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 14444 KB | Output is correct |
2 | Correct | 10 ms | 14444 KB | Output is correct |
3 | Correct | 10 ms | 14444 KB | Output is correct |
4 | Correct | 10 ms | 14444 KB | Output is correct |
5 | Correct | 10 ms | 14444 KB | Output is correct |
6 | Correct | 10 ms | 14444 KB | Output is correct |
7 | Correct | 10 ms | 14444 KB | Output is correct |
8 | Correct | 11 ms | 14444 KB | Output is correct |
9 | Correct | 10 ms | 14444 KB | Output is correct |
10 | Correct | 10 ms | 14444 KB | Output is correct |
11 | Correct | 10 ms | 14444 KB | Output is correct |
12 | Correct | 12 ms | 14444 KB | Output is correct |
13 | Correct | 10 ms | 14444 KB | Output is correct |
14 | Correct | 10 ms | 14444 KB | Output is correct |
15 | Correct | 10 ms | 14444 KB | Output is correct |
16 | Correct | 10 ms | 14444 KB | Output is correct |
17 | Correct | 10 ms | 14444 KB | Output is correct |
18 | Correct | 10 ms | 14444 KB | Output is correct |
19 | Correct | 10 ms | 14444 KB | Output is correct |
20 | Correct | 10 ms | 14444 KB | Output is correct |
21 | Correct | 10 ms | 14444 KB | Output is correct |
22 | Correct | 10 ms | 14572 KB | Output is correct |
23 | Correct | 10 ms | 14444 KB | Output is correct |
24 | Correct | 10 ms | 14444 KB | Output is correct |
25 | Correct | 10 ms | 14444 KB | Output is correct |
26 | Correct | 12 ms | 14444 KB | Output is correct |
27 | Correct | 13 ms | 14444 KB | Output is correct |
28 | Correct | 11 ms | 14464 KB | Output is correct |
29 | Correct | 10 ms | 14444 KB | Output is correct |
30 | Correct | 10 ms | 14444 KB | Output is correct |
31 | Correct | 11 ms | 14444 KB | Output is correct |
32 | Correct | 10 ms | 14444 KB | Output is correct |
33 | Correct | 10 ms | 14444 KB | Output is correct |
34 | Correct | 10 ms | 14444 KB | Output is correct |
35 | Correct | 10 ms | 14444 KB | Output is correct |
36 | Correct | 10 ms | 14444 KB | Output is correct |
37 | Correct | 10 ms | 14444 KB | Output is correct |
38 | Correct | 13 ms | 14444 KB | Output is correct |
39 | Correct | 10 ms | 14444 KB | Output is correct |
40 | Correct | 10 ms | 14444 KB | Output is correct |
41 | Correct | 11 ms | 14444 KB | Output is correct |
42 | Correct | 10 ms | 14444 KB | Output is correct |
43 | Correct | 10 ms | 14444 KB | Output is correct |
44 | Correct | 10 ms | 14444 KB | Output is correct |
45 | Correct | 10 ms | 14444 KB | Output is correct |
46 | Correct | 10 ms | 14444 KB | Output is correct |
47 | Correct | 10 ms | 14444 KB | Output is correct |
48 | Correct | 10 ms | 14444 KB | Output is correct |
49 | Correct | 10 ms | 14444 KB | Output is correct |
50 | Correct | 10 ms | 14444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 14444 KB | Output is correct |
2 | Correct | 10 ms | 14444 KB | Output is correct |
3 | Correct | 10 ms | 14444 KB | Output is correct |
4 | Correct | 10 ms | 14444 KB | Output is correct |
5 | Correct | 10 ms | 14444 KB | Output is correct |
6 | Correct | 10 ms | 14444 KB | Output is correct |
7 | Correct | 10 ms | 14444 KB | Output is correct |
8 | Correct | 11 ms | 14444 KB | Output is correct |
9 | Correct | 10 ms | 14444 KB | Output is correct |
10 | Correct | 10 ms | 14444 KB | Output is correct |
11 | Correct | 10 ms | 14444 KB | Output is correct |
12 | Correct | 12 ms | 14444 KB | Output is correct |
13 | Correct | 10 ms | 14444 KB | Output is correct |
14 | Correct | 10 ms | 14444 KB | Output is correct |
15 | Correct | 10 ms | 14444 KB | Output is correct |
16 | Correct | 10 ms | 14444 KB | Output is correct |
17 | Correct | 10 ms | 14444 KB | Output is correct |
18 | Correct | 10 ms | 14444 KB | Output is correct |
19 | Correct | 10 ms | 14444 KB | Output is correct |
20 | Correct | 10 ms | 14444 KB | Output is correct |
21 | Correct | 10 ms | 14444 KB | Output is correct |
22 | Correct | 10 ms | 14572 KB | Output is correct |
23 | Correct | 10 ms | 14444 KB | Output is correct |
24 | Correct | 10 ms | 14444 KB | Output is correct |
25 | Correct | 10 ms | 14444 KB | Output is correct |
26 | Correct | 12 ms | 14444 KB | Output is correct |
27 | Correct | 13 ms | 14444 KB | Output is correct |
28 | Correct | 11 ms | 14464 KB | Output is correct |
29 | Correct | 10 ms | 14444 KB | Output is correct |
30 | Correct | 10 ms | 14444 KB | Output is correct |
31 | Correct | 11 ms | 14444 KB | Output is correct |
32 | Correct | 10 ms | 14444 KB | Output is correct |
33 | Correct | 10 ms | 14444 KB | Output is correct |
34 | Correct | 10 ms | 14444 KB | Output is correct |
35 | Correct | 10 ms | 14444 KB | Output is correct |
36 | Correct | 10 ms | 14444 KB | Output is correct |
37 | Correct | 10 ms | 14444 KB | Output is correct |
38 | Correct | 13 ms | 14444 KB | Output is correct |
39 | Correct | 10 ms | 14444 KB | Output is correct |
40 | Correct | 10 ms | 14444 KB | Output is correct |
41 | Correct | 11 ms | 14444 KB | Output is correct |
42 | Correct | 10 ms | 14444 KB | Output is correct |
43 | Correct | 10 ms | 14444 KB | Output is correct |
44 | Correct | 10 ms | 14444 KB | Output is correct |
45 | Correct | 10 ms | 14444 KB | Output is correct |
46 | Correct | 10 ms | 14444 KB | Output is correct |
47 | Correct | 10 ms | 14444 KB | Output is correct |
48 | Correct | 10 ms | 14444 KB | Output is correct |
49 | Correct | 10 ms | 14444 KB | Output is correct |
50 | Correct | 10 ms | 14444 KB | Output is correct |
51 | Correct | 12 ms | 14700 KB | Output is correct |
52 | Correct | 16 ms | 14700 KB | Output is correct |
53 | Correct | 14 ms | 14828 KB | Output is correct |
54 | Correct | 12 ms | 14700 KB | Output is correct |
55 | Correct | 12 ms | 14700 KB | Output is correct |
56 | Correct | 13 ms | 14700 KB | Output is correct |
57 | Correct | 12 ms | 14700 KB | Output is correct |
58 | Correct | 12 ms | 14700 KB | Output is correct |
59 | Correct | 12 ms | 14700 KB | Output is correct |
60 | Correct | 13 ms | 14700 KB | Output is correct |
61 | Correct | 13 ms | 14956 KB | Output is correct |
62 | Correct | 13 ms | 14956 KB | Output is correct |
63 | Correct | 12 ms | 14700 KB | Output is correct |
64 | Correct | 12 ms | 14572 KB | Output is correct |
65 | Correct | 11 ms | 14444 KB | Output is correct |
66 | Correct | 12 ms | 14700 KB | Output is correct |
67 | Correct | 13 ms | 14700 KB | Output is correct |
68 | Correct | 12 ms | 14700 KB | Output is correct |
69 | Correct | 13 ms | 14828 KB | Output is correct |
70 | Correct | 12 ms | 14700 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 14444 KB | Output is correct |
2 | Correct | 10 ms | 14444 KB | Output is correct |
3 | Correct | 10 ms | 14444 KB | Output is correct |
4 | Correct | 10 ms | 14444 KB | Output is correct |
5 | Correct | 10 ms | 14444 KB | Output is correct |
6 | Correct | 10 ms | 14444 KB | Output is correct |
7 | Correct | 10 ms | 14444 KB | Output is correct |
8 | Correct | 11 ms | 14444 KB | Output is correct |
9 | Correct | 10 ms | 14444 KB | Output is correct |
10 | Correct | 10 ms | 14444 KB | Output is correct |
11 | Correct | 10 ms | 14444 KB | Output is correct |
12 | Correct | 12 ms | 14444 KB | Output is correct |
13 | Correct | 10 ms | 14444 KB | Output is correct |
14 | Correct | 10 ms | 14444 KB | Output is correct |
15 | Correct | 10 ms | 14444 KB | Output is correct |
16 | Correct | 10 ms | 14444 KB | Output is correct |
17 | Correct | 10 ms | 14444 KB | Output is correct |
18 | Correct | 10 ms | 14444 KB | Output is correct |
19 | Correct | 10 ms | 14444 KB | Output is correct |
20 | Correct | 10 ms | 14444 KB | Output is correct |
21 | Correct | 10 ms | 14444 KB | Output is correct |
22 | Correct | 10 ms | 14572 KB | Output is correct |
23 | Correct | 10 ms | 14444 KB | Output is correct |
24 | Correct | 10 ms | 14444 KB | Output is correct |
25 | Correct | 10 ms | 14444 KB | Output is correct |
26 | Correct | 12 ms | 14444 KB | Output is correct |
27 | Correct | 13 ms | 14444 KB | Output is correct |
28 | Correct | 11 ms | 14464 KB | Output is correct |
29 | Correct | 10 ms | 14444 KB | Output is correct |
30 | Correct | 10 ms | 14444 KB | Output is correct |
31 | Correct | 11 ms | 14444 KB | Output is correct |
32 | Correct | 10 ms | 14444 KB | Output is correct |
33 | Correct | 10 ms | 14444 KB | Output is correct |
34 | Correct | 10 ms | 14444 KB | Output is correct |
35 | Correct | 10 ms | 14444 KB | Output is correct |
36 | Correct | 10 ms | 14444 KB | Output is correct |
37 | Correct | 10 ms | 14444 KB | Output is correct |
38 | Correct | 13 ms | 14444 KB | Output is correct |
39 | Correct | 10 ms | 14444 KB | Output is correct |
40 | Correct | 10 ms | 14444 KB | Output is correct |
41 | Correct | 11 ms | 14444 KB | Output is correct |
42 | Correct | 10 ms | 14444 KB | Output is correct |
43 | Correct | 10 ms | 14444 KB | Output is correct |
44 | Correct | 10 ms | 14444 KB | Output is correct |
45 | Correct | 10 ms | 14444 KB | Output is correct |
46 | Correct | 10 ms | 14444 KB | Output is correct |
47 | Correct | 10 ms | 14444 KB | Output is correct |
48 | Correct | 10 ms | 14444 KB | Output is correct |
49 | Correct | 10 ms | 14444 KB | Output is correct |
50 | Correct | 10 ms | 14444 KB | Output is correct |
51 | Correct | 12 ms | 14700 KB | Output is correct |
52 | Correct | 16 ms | 14700 KB | Output is correct |
53 | Correct | 14 ms | 14828 KB | Output is correct |
54 | Correct | 12 ms | 14700 KB | Output is correct |
55 | Correct | 12 ms | 14700 KB | Output is correct |
56 | Correct | 13 ms | 14700 KB | Output is correct |
57 | Correct | 12 ms | 14700 KB | Output is correct |
58 | Correct | 12 ms | 14700 KB | Output is correct |
59 | Correct | 12 ms | 14700 KB | Output is correct |
60 | Correct | 13 ms | 14700 KB | Output is correct |
61 | Correct | 13 ms | 14956 KB | Output is correct |
62 | Correct | 13 ms | 14956 KB | Output is correct |
63 | Correct | 12 ms | 14700 KB | Output is correct |
64 | Correct | 12 ms | 14572 KB | Output is correct |
65 | Correct | 11 ms | 14444 KB | Output is correct |
66 | Correct | 12 ms | 14700 KB | Output is correct |
67 | Correct | 13 ms | 14700 KB | Output is correct |
68 | Correct | 12 ms | 14700 KB | Output is correct |
69 | Correct | 13 ms | 14828 KB | Output is correct |
70 | Correct | 12 ms | 14700 KB | Output is correct |
71 | Correct | 44 ms | 18284 KB | Output is correct |
72 | Correct | 45 ms | 17772 KB | Output is correct |
73 | Correct | 31 ms | 17004 KB | Output is correct |
74 | Correct | 46 ms | 19948 KB | Output is correct |
75 | Correct | 45 ms | 19584 KB | Output is correct |
76 | Correct | 408 ms | 50028 KB | Output is correct |
77 | Correct | 437 ms | 42476 KB | Output is correct |
78 | Correct | 270 ms | 30820 KB | Output is correct |
79 | Correct | 316 ms | 42456 KB | Output is correct |
80 | Correct | 392 ms | 40044 KB | Output is correct |
81 | Correct | 40 ms | 18284 KB | Output is correct |
82 | Correct | 40 ms | 17772 KB | Output is correct |
83 | Correct | 30 ms | 17132 KB | Output is correct |
84 | Correct | 44 ms | 19820 KB | Output is correct |
85 | Correct | 45 ms | 19436 KB | Output is correct |
86 | Correct | 321 ms | 45236 KB | Output is correct |
87 | Correct | 329 ms | 45080 KB | Output is correct |
88 | Correct | 227 ms | 30820 KB | Output is correct |
89 | Correct | 315 ms | 41964 KB | Output is correct |
90 | Correct | 390 ms | 40172 KB | Output is correct |