# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
251223 |
2020-07-20T15:47:49 Z |
teee |
None (KOI18_family) |
C++14 |
|
399 ms |
75852 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int par[300'010];
int sz[300'010];
int kk;
int find(int n){
return par[n]?par[n]=find(par[n]):n;
}
void merge(int a,int b){
a=find(a);
b=find(b);
if(a^b){
sz[a]+=sz[b];
par[b]=a;
}
}
vector<int> v[2][300'010];
vector<pair<int,pair<int,vector<int>>>> check;
pair<int,int> dfs(int n,int idx){
if(n&&n<=kk){
sz[n]=1;
return {1,n};
}
int cnt=0;
vector<int> t;
int c=0;
for(auto i:v[idx][n]){
pair<int,int> k=dfs(i,idx);
if(k.first>0) {
cnt += k.first;
t.push_back(k.second);
c = k.second;
}
}
if(cnt>1&&t.size()>1)check.push_back({cnt,{-t.size(),t}});
return {cnt,c};
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n1,n2,a;
cin>>n1>>n2>>kk;
for(int i=1;i<=n1;i++){
cin>>a;
v[0][a].push_back(i);
}
for(int i=1;i<=n2;i++){
cin>>a;
v[1][a].push_back(i);
}
dfs(0,0);
dfs(0,1);
sort(check.begin(),check.end());
for(const auto& i:check){
vector<int> t=i.second.second;
int cnt=i.first;
int p=find(t[0]);
for(auto j:t){
merge(p,j);
}
if(sz[find(p)]!=cnt){
cout<<"NO";return 0;
}
}
cout<<"YES";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
Output is correct |
2 |
Correct |
9 ms |
14464 KB |
Output is correct |
3 |
Correct |
9 ms |
14464 KB |
Output is correct |
4 |
Correct |
9 ms |
14464 KB |
Output is correct |
5 |
Correct |
9 ms |
14464 KB |
Output is correct |
6 |
Correct |
9 ms |
14464 KB |
Output is correct |
7 |
Correct |
9 ms |
14464 KB |
Output is correct |
8 |
Correct |
9 ms |
14464 KB |
Output is correct |
9 |
Correct |
9 ms |
14496 KB |
Output is correct |
10 |
Correct |
9 ms |
14464 KB |
Output is correct |
11 |
Correct |
10 ms |
14464 KB |
Output is correct |
12 |
Correct |
10 ms |
14464 KB |
Output is correct |
13 |
Correct |
9 ms |
14464 KB |
Output is correct |
14 |
Correct |
9 ms |
14464 KB |
Output is correct |
15 |
Correct |
9 ms |
14464 KB |
Output is correct |
16 |
Correct |
9 ms |
14464 KB |
Output is correct |
17 |
Correct |
9 ms |
14464 KB |
Output is correct |
18 |
Correct |
9 ms |
14464 KB |
Output is correct |
19 |
Correct |
9 ms |
14464 KB |
Output is correct |
20 |
Correct |
10 ms |
14592 KB |
Output is correct |
21 |
Correct |
10 ms |
14464 KB |
Output is correct |
22 |
Correct |
11 ms |
14464 KB |
Output is correct |
23 |
Correct |
9 ms |
14464 KB |
Output is correct |
24 |
Correct |
9 ms |
14464 KB |
Output is correct |
25 |
Correct |
9 ms |
14464 KB |
Output is correct |
26 |
Correct |
9 ms |
14464 KB |
Output is correct |
27 |
Correct |
9 ms |
14464 KB |
Output is correct |
28 |
Correct |
9 ms |
14464 KB |
Output is correct |
29 |
Correct |
9 ms |
14464 KB |
Output is correct |
30 |
Correct |
9 ms |
14464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
Output is correct |
2 |
Correct |
9 ms |
14464 KB |
Output is correct |
3 |
Correct |
9 ms |
14464 KB |
Output is correct |
4 |
Correct |
9 ms |
14464 KB |
Output is correct |
5 |
Correct |
9 ms |
14464 KB |
Output is correct |
6 |
Correct |
9 ms |
14464 KB |
Output is correct |
7 |
Correct |
9 ms |
14464 KB |
Output is correct |
8 |
Correct |
9 ms |
14464 KB |
Output is correct |
9 |
Correct |
9 ms |
14496 KB |
Output is correct |
10 |
Correct |
9 ms |
14464 KB |
Output is correct |
11 |
Correct |
10 ms |
14464 KB |
Output is correct |
12 |
Correct |
10 ms |
14464 KB |
Output is correct |
13 |
Correct |
9 ms |
14464 KB |
Output is correct |
14 |
Correct |
9 ms |
14464 KB |
Output is correct |
15 |
Correct |
9 ms |
14464 KB |
Output is correct |
16 |
Correct |
9 ms |
14464 KB |
Output is correct |
17 |
Correct |
9 ms |
14464 KB |
Output is correct |
18 |
Correct |
9 ms |
14464 KB |
Output is correct |
19 |
Correct |
9 ms |
14464 KB |
Output is correct |
20 |
Correct |
10 ms |
14592 KB |
Output is correct |
21 |
Correct |
10 ms |
14464 KB |
Output is correct |
22 |
Correct |
11 ms |
14464 KB |
Output is correct |
23 |
Correct |
9 ms |
14464 KB |
Output is correct |
24 |
Correct |
9 ms |
14464 KB |
Output is correct |
25 |
Correct |
9 ms |
14464 KB |
Output is correct |
26 |
Correct |
9 ms |
14464 KB |
Output is correct |
27 |
Correct |
9 ms |
14464 KB |
Output is correct |
28 |
Correct |
9 ms |
14464 KB |
Output is correct |
29 |
Correct |
9 ms |
14464 KB |
Output is correct |
30 |
Correct |
9 ms |
14464 KB |
Output is correct |
31 |
Correct |
8 ms |
14464 KB |
Output is correct |
32 |
Correct |
9 ms |
14464 KB |
Output is correct |
33 |
Correct |
9 ms |
14464 KB |
Output is correct |
34 |
Correct |
9 ms |
14464 KB |
Output is correct |
35 |
Correct |
12 ms |
14464 KB |
Output is correct |
36 |
Correct |
9 ms |
14464 KB |
Output is correct |
37 |
Correct |
8 ms |
14464 KB |
Output is correct |
38 |
Correct |
12 ms |
14464 KB |
Output is correct |
39 |
Correct |
9 ms |
14464 KB |
Output is correct |
40 |
Correct |
9 ms |
14464 KB |
Output is correct |
41 |
Correct |
9 ms |
14464 KB |
Output is correct |
42 |
Correct |
9 ms |
14464 KB |
Output is correct |
43 |
Correct |
10 ms |
14464 KB |
Output is correct |
44 |
Correct |
9 ms |
14464 KB |
Output is correct |
45 |
Correct |
9 ms |
14464 KB |
Output is correct |
46 |
Correct |
12 ms |
14464 KB |
Output is correct |
47 |
Correct |
9 ms |
14464 KB |
Output is correct |
48 |
Correct |
12 ms |
14464 KB |
Output is correct |
49 |
Correct |
9 ms |
14464 KB |
Output is correct |
50 |
Correct |
9 ms |
14464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
Output is correct |
2 |
Correct |
9 ms |
14464 KB |
Output is correct |
3 |
Correct |
9 ms |
14464 KB |
Output is correct |
4 |
Correct |
9 ms |
14464 KB |
Output is correct |
5 |
Correct |
9 ms |
14464 KB |
Output is correct |
6 |
Correct |
9 ms |
14464 KB |
Output is correct |
7 |
Correct |
9 ms |
14464 KB |
Output is correct |
8 |
Correct |
9 ms |
14464 KB |
Output is correct |
9 |
Correct |
9 ms |
14496 KB |
Output is correct |
10 |
Correct |
9 ms |
14464 KB |
Output is correct |
11 |
Correct |
10 ms |
14464 KB |
Output is correct |
12 |
Correct |
10 ms |
14464 KB |
Output is correct |
13 |
Correct |
9 ms |
14464 KB |
Output is correct |
14 |
Correct |
9 ms |
14464 KB |
Output is correct |
15 |
Correct |
9 ms |
14464 KB |
Output is correct |
16 |
Correct |
9 ms |
14464 KB |
Output is correct |
17 |
Correct |
9 ms |
14464 KB |
Output is correct |
18 |
Correct |
9 ms |
14464 KB |
Output is correct |
19 |
Correct |
9 ms |
14464 KB |
Output is correct |
20 |
Correct |
10 ms |
14592 KB |
Output is correct |
21 |
Correct |
10 ms |
14464 KB |
Output is correct |
22 |
Correct |
11 ms |
14464 KB |
Output is correct |
23 |
Correct |
9 ms |
14464 KB |
Output is correct |
24 |
Correct |
9 ms |
14464 KB |
Output is correct |
25 |
Correct |
9 ms |
14464 KB |
Output is correct |
26 |
Correct |
9 ms |
14464 KB |
Output is correct |
27 |
Correct |
9 ms |
14464 KB |
Output is correct |
28 |
Correct |
9 ms |
14464 KB |
Output is correct |
29 |
Correct |
9 ms |
14464 KB |
Output is correct |
30 |
Correct |
9 ms |
14464 KB |
Output is correct |
31 |
Correct |
8 ms |
14464 KB |
Output is correct |
32 |
Correct |
9 ms |
14464 KB |
Output is correct |
33 |
Correct |
9 ms |
14464 KB |
Output is correct |
34 |
Correct |
9 ms |
14464 KB |
Output is correct |
35 |
Correct |
12 ms |
14464 KB |
Output is correct |
36 |
Correct |
9 ms |
14464 KB |
Output is correct |
37 |
Correct |
8 ms |
14464 KB |
Output is correct |
38 |
Correct |
12 ms |
14464 KB |
Output is correct |
39 |
Correct |
9 ms |
14464 KB |
Output is correct |
40 |
Correct |
9 ms |
14464 KB |
Output is correct |
41 |
Correct |
9 ms |
14464 KB |
Output is correct |
42 |
Correct |
9 ms |
14464 KB |
Output is correct |
43 |
Correct |
10 ms |
14464 KB |
Output is correct |
44 |
Correct |
9 ms |
14464 KB |
Output is correct |
45 |
Correct |
9 ms |
14464 KB |
Output is correct |
46 |
Correct |
12 ms |
14464 KB |
Output is correct |
47 |
Correct |
9 ms |
14464 KB |
Output is correct |
48 |
Correct |
12 ms |
14464 KB |
Output is correct |
49 |
Correct |
9 ms |
14464 KB |
Output is correct |
50 |
Correct |
9 ms |
14464 KB |
Output is correct |
51 |
Correct |
10 ms |
14592 KB |
Output is correct |
52 |
Correct |
12 ms |
14976 KB |
Output is correct |
53 |
Correct |
12 ms |
14976 KB |
Output is correct |
54 |
Correct |
11 ms |
14720 KB |
Output is correct |
55 |
Correct |
10 ms |
14592 KB |
Output is correct |
56 |
Correct |
10 ms |
14720 KB |
Output is correct |
57 |
Correct |
11 ms |
14720 KB |
Output is correct |
58 |
Correct |
11 ms |
14720 KB |
Output is correct |
59 |
Correct |
11 ms |
14720 KB |
Output is correct |
60 |
Correct |
10 ms |
14592 KB |
Output is correct |
61 |
Correct |
12 ms |
15584 KB |
Output is correct |
62 |
Correct |
13 ms |
15584 KB |
Output is correct |
63 |
Correct |
12 ms |
14592 KB |
Output is correct |
64 |
Correct |
11 ms |
14720 KB |
Output is correct |
65 |
Correct |
9 ms |
14464 KB |
Output is correct |
66 |
Correct |
11 ms |
14848 KB |
Output is correct |
67 |
Correct |
11 ms |
14720 KB |
Output is correct |
68 |
Correct |
11 ms |
14720 KB |
Output is correct |
69 |
Correct |
12 ms |
14976 KB |
Output is correct |
70 |
Correct |
10 ms |
14592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14464 KB |
Output is correct |
2 |
Correct |
9 ms |
14464 KB |
Output is correct |
3 |
Correct |
9 ms |
14464 KB |
Output is correct |
4 |
Correct |
9 ms |
14464 KB |
Output is correct |
5 |
Correct |
9 ms |
14464 KB |
Output is correct |
6 |
Correct |
9 ms |
14464 KB |
Output is correct |
7 |
Correct |
9 ms |
14464 KB |
Output is correct |
8 |
Correct |
9 ms |
14464 KB |
Output is correct |
9 |
Correct |
9 ms |
14496 KB |
Output is correct |
10 |
Correct |
9 ms |
14464 KB |
Output is correct |
11 |
Correct |
10 ms |
14464 KB |
Output is correct |
12 |
Correct |
10 ms |
14464 KB |
Output is correct |
13 |
Correct |
9 ms |
14464 KB |
Output is correct |
14 |
Correct |
9 ms |
14464 KB |
Output is correct |
15 |
Correct |
9 ms |
14464 KB |
Output is correct |
16 |
Correct |
9 ms |
14464 KB |
Output is correct |
17 |
Correct |
9 ms |
14464 KB |
Output is correct |
18 |
Correct |
9 ms |
14464 KB |
Output is correct |
19 |
Correct |
9 ms |
14464 KB |
Output is correct |
20 |
Correct |
10 ms |
14592 KB |
Output is correct |
21 |
Correct |
10 ms |
14464 KB |
Output is correct |
22 |
Correct |
11 ms |
14464 KB |
Output is correct |
23 |
Correct |
9 ms |
14464 KB |
Output is correct |
24 |
Correct |
9 ms |
14464 KB |
Output is correct |
25 |
Correct |
9 ms |
14464 KB |
Output is correct |
26 |
Correct |
9 ms |
14464 KB |
Output is correct |
27 |
Correct |
9 ms |
14464 KB |
Output is correct |
28 |
Correct |
9 ms |
14464 KB |
Output is correct |
29 |
Correct |
9 ms |
14464 KB |
Output is correct |
30 |
Correct |
9 ms |
14464 KB |
Output is correct |
31 |
Correct |
8 ms |
14464 KB |
Output is correct |
32 |
Correct |
9 ms |
14464 KB |
Output is correct |
33 |
Correct |
9 ms |
14464 KB |
Output is correct |
34 |
Correct |
9 ms |
14464 KB |
Output is correct |
35 |
Correct |
12 ms |
14464 KB |
Output is correct |
36 |
Correct |
9 ms |
14464 KB |
Output is correct |
37 |
Correct |
8 ms |
14464 KB |
Output is correct |
38 |
Correct |
12 ms |
14464 KB |
Output is correct |
39 |
Correct |
9 ms |
14464 KB |
Output is correct |
40 |
Correct |
9 ms |
14464 KB |
Output is correct |
41 |
Correct |
9 ms |
14464 KB |
Output is correct |
42 |
Correct |
9 ms |
14464 KB |
Output is correct |
43 |
Correct |
10 ms |
14464 KB |
Output is correct |
44 |
Correct |
9 ms |
14464 KB |
Output is correct |
45 |
Correct |
9 ms |
14464 KB |
Output is correct |
46 |
Correct |
12 ms |
14464 KB |
Output is correct |
47 |
Correct |
9 ms |
14464 KB |
Output is correct |
48 |
Correct |
12 ms |
14464 KB |
Output is correct |
49 |
Correct |
9 ms |
14464 KB |
Output is correct |
50 |
Correct |
9 ms |
14464 KB |
Output is correct |
51 |
Correct |
10 ms |
14592 KB |
Output is correct |
52 |
Correct |
12 ms |
14976 KB |
Output is correct |
53 |
Correct |
12 ms |
14976 KB |
Output is correct |
54 |
Correct |
11 ms |
14720 KB |
Output is correct |
55 |
Correct |
10 ms |
14592 KB |
Output is correct |
56 |
Correct |
10 ms |
14720 KB |
Output is correct |
57 |
Correct |
11 ms |
14720 KB |
Output is correct |
58 |
Correct |
11 ms |
14720 KB |
Output is correct |
59 |
Correct |
11 ms |
14720 KB |
Output is correct |
60 |
Correct |
10 ms |
14592 KB |
Output is correct |
61 |
Correct |
12 ms |
15584 KB |
Output is correct |
62 |
Correct |
13 ms |
15584 KB |
Output is correct |
63 |
Correct |
12 ms |
14592 KB |
Output is correct |
64 |
Correct |
11 ms |
14720 KB |
Output is correct |
65 |
Correct |
9 ms |
14464 KB |
Output is correct |
66 |
Correct |
11 ms |
14848 KB |
Output is correct |
67 |
Correct |
11 ms |
14720 KB |
Output is correct |
68 |
Correct |
11 ms |
14720 KB |
Output is correct |
69 |
Correct |
12 ms |
14976 KB |
Output is correct |
70 |
Correct |
10 ms |
14592 KB |
Output is correct |
71 |
Correct |
42 ms |
18832 KB |
Output is correct |
72 |
Correct |
51 ms |
18444 KB |
Output is correct |
73 |
Correct |
31 ms |
16768 KB |
Output is correct |
74 |
Correct |
49 ms |
21120 KB |
Output is correct |
75 |
Correct |
48 ms |
19576 KB |
Output is correct |
76 |
Correct |
399 ms |
58236 KB |
Output is correct |
77 |
Correct |
354 ms |
35672 KB |
Output is correct |
78 |
Correct |
241 ms |
31196 KB |
Output is correct |
79 |
Correct |
296 ms |
46328 KB |
Output is correct |
80 |
Correct |
286 ms |
34168 KB |
Output is correct |
81 |
Correct |
41 ms |
18832 KB |
Output is correct |
82 |
Correct |
46 ms |
18444 KB |
Output is correct |
83 |
Correct |
25 ms |
16896 KB |
Output is correct |
84 |
Correct |
44 ms |
20768 KB |
Output is correct |
85 |
Correct |
41 ms |
19448 KB |
Output is correct |
86 |
Correct |
392 ms |
75852 KB |
Output is correct |
87 |
Correct |
377 ms |
75724 KB |
Output is correct |
88 |
Correct |
267 ms |
31200 KB |
Output is correct |
89 |
Correct |
336 ms |
44420 KB |
Output is correct |
90 |
Correct |
347 ms |
34560 KB |
Output is correct |