#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;
typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements
#define DEBUG
#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
struct rng{ int num,t,u; };
int n[2],k,p,num[2][300005],rep[2][300005],par[300005],sz[300005];
vi AL[2][300005];
vector<rng> rngs;
void dfs(int t,int u){
if(u!=0&&u<=k){
num[t][u]=1;
rep[t][u]=u;
}
for(int v:AL[t][u]){
dfs(t,v);
num[t][u]+=num[t][v];
rep[t][u]=rep[t][v];
}
if(num[t][u]>1)rngs.push_back({num[t][u],t,u});
}
int fp(int i){
return (par[i]==i)?i:par[i]=fp(par[i]);
}
void join(int x,int y){
x=fp(x),y=fp(y);
if(x==y)return;
if(sz[x]<sz[y])swap(x,y);
par[y]=x;sz[x]+=sz[y];
}
int main(){
sf("%d%d%d",&n[0],&n[1],&k);
for(int t=0;t<2;++t){
for(int i=1;i<=n[t];++i){
sf("%d",&p);
AL[t][p].pb(i);
}
}
dfs(0,0);dfs(1,0);
sort(all(rngs),[&](rng a,rng b){return a.num<b.num;});
for(int i=1;i<=k;++i){
par[i]=i;sz[i]=1;
}
for(rng r:rngs){
for(int v:AL[r.t][r.u]){
join(rep[r.t][r.u],rep[r.t][v]);
}
if(sz(AL[r.t][r.u])<=1)continue;
if(sz[fp(rep[r.t][r.u])]!=r.num){
pf("NO\n");
return 0;
}
}
pf("YES\n");
}
Compilation message
family.cpp: In function 'int main()':
family.cpp:72:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | sf("%d%d%d",&n[0],&n[1],&k);
| ^
family.cpp:75:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | sf("%d",&p);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14396 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
9 ms |
14400 KB |
Output is correct |
4 |
Correct |
8 ms |
14412 KB |
Output is correct |
5 |
Correct |
9 ms |
14412 KB |
Output is correct |
6 |
Correct |
10 ms |
14412 KB |
Output is correct |
7 |
Correct |
8 ms |
14392 KB |
Output is correct |
8 |
Correct |
8 ms |
14380 KB |
Output is correct |
9 |
Correct |
11 ms |
14396 KB |
Output is correct |
10 |
Correct |
9 ms |
14412 KB |
Output is correct |
11 |
Correct |
10 ms |
14412 KB |
Output is correct |
12 |
Correct |
9 ms |
14396 KB |
Output is correct |
13 |
Correct |
8 ms |
14396 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
9 ms |
14412 KB |
Output is correct |
16 |
Correct |
9 ms |
14392 KB |
Output is correct |
17 |
Correct |
8 ms |
14404 KB |
Output is correct |
18 |
Correct |
8 ms |
14412 KB |
Output is correct |
19 |
Correct |
8 ms |
14400 KB |
Output is correct |
20 |
Correct |
8 ms |
14384 KB |
Output is correct |
21 |
Correct |
9 ms |
14400 KB |
Output is correct |
22 |
Correct |
9 ms |
14412 KB |
Output is correct |
23 |
Correct |
9 ms |
14412 KB |
Output is correct |
24 |
Correct |
9 ms |
14412 KB |
Output is correct |
25 |
Correct |
9 ms |
14364 KB |
Output is correct |
26 |
Correct |
9 ms |
14412 KB |
Output is correct |
27 |
Correct |
9 ms |
14412 KB |
Output is correct |
28 |
Correct |
9 ms |
14392 KB |
Output is correct |
29 |
Correct |
9 ms |
14412 KB |
Output is correct |
30 |
Correct |
9 ms |
14412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14396 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
9 ms |
14400 KB |
Output is correct |
4 |
Correct |
8 ms |
14412 KB |
Output is correct |
5 |
Correct |
9 ms |
14412 KB |
Output is correct |
6 |
Correct |
10 ms |
14412 KB |
Output is correct |
7 |
Correct |
8 ms |
14392 KB |
Output is correct |
8 |
Correct |
8 ms |
14380 KB |
Output is correct |
9 |
Correct |
11 ms |
14396 KB |
Output is correct |
10 |
Correct |
9 ms |
14412 KB |
Output is correct |
11 |
Correct |
10 ms |
14412 KB |
Output is correct |
12 |
Correct |
9 ms |
14396 KB |
Output is correct |
13 |
Correct |
8 ms |
14396 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
9 ms |
14412 KB |
Output is correct |
16 |
Correct |
9 ms |
14392 KB |
Output is correct |
17 |
Correct |
8 ms |
14404 KB |
Output is correct |
18 |
Correct |
8 ms |
14412 KB |
Output is correct |
19 |
Correct |
8 ms |
14400 KB |
Output is correct |
20 |
Correct |
8 ms |
14384 KB |
Output is correct |
21 |
Correct |
9 ms |
14400 KB |
Output is correct |
22 |
Correct |
9 ms |
14412 KB |
Output is correct |
23 |
Correct |
9 ms |
14412 KB |
Output is correct |
24 |
Correct |
9 ms |
14412 KB |
Output is correct |
25 |
Correct |
9 ms |
14364 KB |
Output is correct |
26 |
Correct |
9 ms |
14412 KB |
Output is correct |
27 |
Correct |
9 ms |
14412 KB |
Output is correct |
28 |
Correct |
9 ms |
14392 KB |
Output is correct |
29 |
Correct |
9 ms |
14412 KB |
Output is correct |
30 |
Correct |
9 ms |
14412 KB |
Output is correct |
31 |
Correct |
9 ms |
14348 KB |
Output is correct |
32 |
Correct |
10 ms |
14396 KB |
Output is correct |
33 |
Correct |
9 ms |
14352 KB |
Output is correct |
34 |
Correct |
10 ms |
14412 KB |
Output is correct |
35 |
Correct |
10 ms |
14412 KB |
Output is correct |
36 |
Correct |
9 ms |
14340 KB |
Output is correct |
37 |
Correct |
9 ms |
14448 KB |
Output is correct |
38 |
Correct |
9 ms |
14412 KB |
Output is correct |
39 |
Correct |
9 ms |
14400 KB |
Output is correct |
40 |
Correct |
9 ms |
14396 KB |
Output is correct |
41 |
Correct |
9 ms |
14404 KB |
Output is correct |
42 |
Correct |
9 ms |
14396 KB |
Output is correct |
43 |
Correct |
9 ms |
14412 KB |
Output is correct |
44 |
Correct |
8 ms |
14412 KB |
Output is correct |
45 |
Correct |
9 ms |
14388 KB |
Output is correct |
46 |
Correct |
9 ms |
14400 KB |
Output is correct |
47 |
Correct |
9 ms |
14412 KB |
Output is correct |
48 |
Correct |
10 ms |
14392 KB |
Output is correct |
49 |
Correct |
10 ms |
14412 KB |
Output is correct |
50 |
Correct |
12 ms |
14440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14396 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
9 ms |
14400 KB |
Output is correct |
4 |
Correct |
8 ms |
14412 KB |
Output is correct |
5 |
Correct |
9 ms |
14412 KB |
Output is correct |
6 |
Correct |
10 ms |
14412 KB |
Output is correct |
7 |
Correct |
8 ms |
14392 KB |
Output is correct |
8 |
Correct |
8 ms |
14380 KB |
Output is correct |
9 |
Correct |
11 ms |
14396 KB |
Output is correct |
10 |
Correct |
9 ms |
14412 KB |
Output is correct |
11 |
Correct |
10 ms |
14412 KB |
Output is correct |
12 |
Correct |
9 ms |
14396 KB |
Output is correct |
13 |
Correct |
8 ms |
14396 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
9 ms |
14412 KB |
Output is correct |
16 |
Correct |
9 ms |
14392 KB |
Output is correct |
17 |
Correct |
8 ms |
14404 KB |
Output is correct |
18 |
Correct |
8 ms |
14412 KB |
Output is correct |
19 |
Correct |
8 ms |
14400 KB |
Output is correct |
20 |
Correct |
8 ms |
14384 KB |
Output is correct |
21 |
Correct |
9 ms |
14400 KB |
Output is correct |
22 |
Correct |
9 ms |
14412 KB |
Output is correct |
23 |
Correct |
9 ms |
14412 KB |
Output is correct |
24 |
Correct |
9 ms |
14412 KB |
Output is correct |
25 |
Correct |
9 ms |
14364 KB |
Output is correct |
26 |
Correct |
9 ms |
14412 KB |
Output is correct |
27 |
Correct |
9 ms |
14412 KB |
Output is correct |
28 |
Correct |
9 ms |
14392 KB |
Output is correct |
29 |
Correct |
9 ms |
14412 KB |
Output is correct |
30 |
Correct |
9 ms |
14412 KB |
Output is correct |
31 |
Correct |
9 ms |
14348 KB |
Output is correct |
32 |
Correct |
10 ms |
14396 KB |
Output is correct |
33 |
Correct |
9 ms |
14352 KB |
Output is correct |
34 |
Correct |
10 ms |
14412 KB |
Output is correct |
35 |
Correct |
10 ms |
14412 KB |
Output is correct |
36 |
Correct |
9 ms |
14340 KB |
Output is correct |
37 |
Correct |
9 ms |
14448 KB |
Output is correct |
38 |
Correct |
9 ms |
14412 KB |
Output is correct |
39 |
Correct |
9 ms |
14400 KB |
Output is correct |
40 |
Correct |
9 ms |
14396 KB |
Output is correct |
41 |
Correct |
9 ms |
14404 KB |
Output is correct |
42 |
Correct |
9 ms |
14396 KB |
Output is correct |
43 |
Correct |
9 ms |
14412 KB |
Output is correct |
44 |
Correct |
8 ms |
14412 KB |
Output is correct |
45 |
Correct |
9 ms |
14388 KB |
Output is correct |
46 |
Correct |
9 ms |
14400 KB |
Output is correct |
47 |
Correct |
9 ms |
14412 KB |
Output is correct |
48 |
Correct |
10 ms |
14392 KB |
Output is correct |
49 |
Correct |
10 ms |
14412 KB |
Output is correct |
50 |
Correct |
12 ms |
14440 KB |
Output is correct |
51 |
Correct |
10 ms |
14540 KB |
Output is correct |
52 |
Correct |
11 ms |
14668 KB |
Output is correct |
53 |
Correct |
11 ms |
14788 KB |
Output is correct |
54 |
Correct |
10 ms |
14668 KB |
Output is correct |
55 |
Correct |
11 ms |
14628 KB |
Output is correct |
56 |
Correct |
11 ms |
14668 KB |
Output is correct |
57 |
Correct |
11 ms |
14540 KB |
Output is correct |
58 |
Correct |
11 ms |
14668 KB |
Output is correct |
59 |
Correct |
12 ms |
14660 KB |
Output is correct |
60 |
Correct |
10 ms |
14532 KB |
Output is correct |
61 |
Correct |
12 ms |
15104 KB |
Output is correct |
62 |
Correct |
13 ms |
15164 KB |
Output is correct |
63 |
Correct |
11 ms |
14544 KB |
Output is correct |
64 |
Correct |
10 ms |
14536 KB |
Output is correct |
65 |
Correct |
10 ms |
14464 KB |
Output is correct |
66 |
Correct |
11 ms |
14660 KB |
Output is correct |
67 |
Correct |
10 ms |
14668 KB |
Output is correct |
68 |
Correct |
11 ms |
14636 KB |
Output is correct |
69 |
Correct |
12 ms |
14788 KB |
Output is correct |
70 |
Correct |
10 ms |
14536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14396 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
9 ms |
14400 KB |
Output is correct |
4 |
Correct |
8 ms |
14412 KB |
Output is correct |
5 |
Correct |
9 ms |
14412 KB |
Output is correct |
6 |
Correct |
10 ms |
14412 KB |
Output is correct |
7 |
Correct |
8 ms |
14392 KB |
Output is correct |
8 |
Correct |
8 ms |
14380 KB |
Output is correct |
9 |
Correct |
11 ms |
14396 KB |
Output is correct |
10 |
Correct |
9 ms |
14412 KB |
Output is correct |
11 |
Correct |
10 ms |
14412 KB |
Output is correct |
12 |
Correct |
9 ms |
14396 KB |
Output is correct |
13 |
Correct |
8 ms |
14396 KB |
Output is correct |
14 |
Correct |
10 ms |
14444 KB |
Output is correct |
15 |
Correct |
9 ms |
14412 KB |
Output is correct |
16 |
Correct |
9 ms |
14392 KB |
Output is correct |
17 |
Correct |
8 ms |
14404 KB |
Output is correct |
18 |
Correct |
8 ms |
14412 KB |
Output is correct |
19 |
Correct |
8 ms |
14400 KB |
Output is correct |
20 |
Correct |
8 ms |
14384 KB |
Output is correct |
21 |
Correct |
9 ms |
14400 KB |
Output is correct |
22 |
Correct |
9 ms |
14412 KB |
Output is correct |
23 |
Correct |
9 ms |
14412 KB |
Output is correct |
24 |
Correct |
9 ms |
14412 KB |
Output is correct |
25 |
Correct |
9 ms |
14364 KB |
Output is correct |
26 |
Correct |
9 ms |
14412 KB |
Output is correct |
27 |
Correct |
9 ms |
14412 KB |
Output is correct |
28 |
Correct |
9 ms |
14392 KB |
Output is correct |
29 |
Correct |
9 ms |
14412 KB |
Output is correct |
30 |
Correct |
9 ms |
14412 KB |
Output is correct |
31 |
Correct |
9 ms |
14348 KB |
Output is correct |
32 |
Correct |
10 ms |
14396 KB |
Output is correct |
33 |
Correct |
9 ms |
14352 KB |
Output is correct |
34 |
Correct |
10 ms |
14412 KB |
Output is correct |
35 |
Correct |
10 ms |
14412 KB |
Output is correct |
36 |
Correct |
9 ms |
14340 KB |
Output is correct |
37 |
Correct |
9 ms |
14448 KB |
Output is correct |
38 |
Correct |
9 ms |
14412 KB |
Output is correct |
39 |
Correct |
9 ms |
14400 KB |
Output is correct |
40 |
Correct |
9 ms |
14396 KB |
Output is correct |
41 |
Correct |
9 ms |
14404 KB |
Output is correct |
42 |
Correct |
9 ms |
14396 KB |
Output is correct |
43 |
Correct |
9 ms |
14412 KB |
Output is correct |
44 |
Correct |
8 ms |
14412 KB |
Output is correct |
45 |
Correct |
9 ms |
14388 KB |
Output is correct |
46 |
Correct |
9 ms |
14400 KB |
Output is correct |
47 |
Correct |
9 ms |
14412 KB |
Output is correct |
48 |
Correct |
10 ms |
14392 KB |
Output is correct |
49 |
Correct |
10 ms |
14412 KB |
Output is correct |
50 |
Correct |
12 ms |
14440 KB |
Output is correct |
51 |
Correct |
10 ms |
14540 KB |
Output is correct |
52 |
Correct |
11 ms |
14668 KB |
Output is correct |
53 |
Correct |
11 ms |
14788 KB |
Output is correct |
54 |
Correct |
10 ms |
14668 KB |
Output is correct |
55 |
Correct |
11 ms |
14628 KB |
Output is correct |
56 |
Correct |
11 ms |
14668 KB |
Output is correct |
57 |
Correct |
11 ms |
14540 KB |
Output is correct |
58 |
Correct |
11 ms |
14668 KB |
Output is correct |
59 |
Correct |
12 ms |
14660 KB |
Output is correct |
60 |
Correct |
10 ms |
14532 KB |
Output is correct |
61 |
Correct |
12 ms |
15104 KB |
Output is correct |
62 |
Correct |
13 ms |
15164 KB |
Output is correct |
63 |
Correct |
11 ms |
14544 KB |
Output is correct |
64 |
Correct |
10 ms |
14536 KB |
Output is correct |
65 |
Correct |
10 ms |
14464 KB |
Output is correct |
66 |
Correct |
11 ms |
14660 KB |
Output is correct |
67 |
Correct |
10 ms |
14668 KB |
Output is correct |
68 |
Correct |
11 ms |
14636 KB |
Output is correct |
69 |
Correct |
12 ms |
14788 KB |
Output is correct |
70 |
Correct |
10 ms |
14536 KB |
Output is correct |
71 |
Correct |
41 ms |
18756 KB |
Output is correct |
72 |
Correct |
40 ms |
18020 KB |
Output is correct |
73 |
Correct |
28 ms |
17548 KB |
Output is correct |
74 |
Correct |
44 ms |
21828 KB |
Output is correct |
75 |
Correct |
49 ms |
21184 KB |
Output is correct |
76 |
Correct |
357 ms |
63704 KB |
Output is correct |
77 |
Correct |
435 ms |
49728 KB |
Output is correct |
78 |
Correct |
257 ms |
31292 KB |
Output is correct |
79 |
Correct |
325 ms |
54456 KB |
Output is correct |
80 |
Correct |
367 ms |
47528 KB |
Output is correct |
81 |
Correct |
37 ms |
18732 KB |
Output is correct |
82 |
Correct |
45 ms |
17936 KB |
Output is correct |
83 |
Correct |
25 ms |
17676 KB |
Output is correct |
84 |
Correct |
43 ms |
21388 KB |
Output is correct |
85 |
Correct |
44 ms |
21240 KB |
Output is correct |
86 |
Correct |
295 ms |
57576 KB |
Output is correct |
87 |
Correct |
284 ms |
57644 KB |
Output is correct |
88 |
Correct |
210 ms |
31276 KB |
Output is correct |
89 |
Correct |
305 ms |
52808 KB |
Output is correct |
90 |
Correct |
334 ms |
47952 KB |
Output is correct |