답안 #333100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333100 2020-12-04T13:49:38 Z oolimry 족보 (KOI18_family) C++14
100 / 100
386 ms 63852 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int,int> ii;

int n1, n2, K; 
vector<int> child[2][300005];
int num[2][300005];
int rep[2][300005];
struct check{ int num, u, t; };
vector<check> stuff;

void dfs(int t, int u){
	if(num[t][u] != 0) return;
	if(u != 0 && u <= K){
		num[t][u] = 1;
		rep[t][u] = u;
	}
	else{
		for(int v : child[t][u]){
			dfs(t, v);
			num[t][u] += num[t][v];
			rep[t][u] = rep[t][v];
		}
		if(num[t][u] > 1 && (int) child[t][u].size() > 1) stuff.push_back({num[t][u], u, t});
		///idk why child[t][u].size() > 1 is needed .-.
	}
}

int p[300005];
int sz[300005];
int findSet(int u){
	if(p[u] == u) return u;
	else return p[u] = findSet(p[u]);
}
void unionSet(int u, int v){
	u = findSet(u), v = findSet(v);
	if(u == v) return;
	if(u&1) swap(u,v);
	p[u] = v;
	sz[v] += sz[u];
}
int getSz(int u){
	return sz[findSet(u)];
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n1 >> n2 >> K;
	
	for(int i = 1;i <= n1;i++){
		int a; cin >> a;
		child[0][a].push_back(i);
	}
	for(int i = 1;i <= n2;i++){
		int a; cin >> a;
		child[1][a].push_back(i);
	}
	
	//for(int i = 1;i <= n1;i++) dfs(0, i);
	//for(int i = 1;i <= n2;i++) dfs(1, i);
	
	dfs(0, 0); dfs(1, 0);
	
	for(int i = 1;i <= K;i++){
		p[i] = i;
		sz[i] = 1;
	}
		
	sort(all(stuff), [&](check a, check b){ return a.num < b.num; });
	
	for(check C : stuff){
		for(int v : child[C.t][C.u]){
			unionSet(rep[C.t][C.u], rep[C.t][v]);
		} 
		if(getSz(rep[C.t][C.u]) != C.num){
			cout << "NO";
			return 0;
		}
	}
	
	
	cout << "YES";
}
# 결과 실행 시간 메모리 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 10 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 11 ms 14444 KB Output is correct
12 Correct 10 ms 14444 KB Output is correct
13 Correct 10 ms 14452 KB Output is correct
14 Correct 10 ms 14444 KB Output is correct
15 Correct 10 ms 14444 KB Output is correct
16 Correct 11 ms 14444 KB Output is correct
17 Correct 11 ms 14444 KB Output is correct
18 Correct 10 ms 14444 KB Output is correct
19 Correct 11 ms 14444 KB Output is correct
20 Correct 10 ms 14444 KB Output is correct
21 Correct 11 ms 14444 KB Output is correct
22 Correct 11 ms 14444 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 10 ms 14444 KB Output is correct
27 Correct 10 ms 14444 KB Output is correct
28 Correct 10 ms 14444 KB Output is correct
29 Correct 10 ms 14444 KB Output is correct
30 Correct 10 ms 14444 KB Output is correct
# 결과 실행 시간 메모리 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 10 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 11 ms 14444 KB Output is correct
12 Correct 10 ms 14444 KB Output is correct
13 Correct 10 ms 14452 KB Output is correct
14 Correct 10 ms 14444 KB Output is correct
15 Correct 10 ms 14444 KB Output is correct
16 Correct 11 ms 14444 KB Output is correct
17 Correct 11 ms 14444 KB Output is correct
18 Correct 10 ms 14444 KB Output is correct
19 Correct 11 ms 14444 KB Output is correct
20 Correct 10 ms 14444 KB Output is correct
21 Correct 11 ms 14444 KB Output is correct
22 Correct 11 ms 14444 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 10 ms 14444 KB Output is correct
27 Correct 10 ms 14444 KB Output is correct
28 Correct 10 ms 14444 KB Output is correct
29 Correct 10 ms 14444 KB Output is correct
30 Correct 10 ms 14444 KB Output is correct
31 Correct 10 ms 14444 KB Output is correct
32 Correct 14 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 11 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 10 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 10 ms 14444 KB Output is correct
42 Correct 12 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
# 결과 실행 시간 메모리 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 10 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 11 ms 14444 KB Output is correct
12 Correct 10 ms 14444 KB Output is correct
13 Correct 10 ms 14452 KB Output is correct
14 Correct 10 ms 14444 KB Output is correct
15 Correct 10 ms 14444 KB Output is correct
16 Correct 11 ms 14444 KB Output is correct
17 Correct 11 ms 14444 KB Output is correct
18 Correct 10 ms 14444 KB Output is correct
19 Correct 11 ms 14444 KB Output is correct
20 Correct 10 ms 14444 KB Output is correct
21 Correct 11 ms 14444 KB Output is correct
22 Correct 11 ms 14444 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 10 ms 14444 KB Output is correct
27 Correct 10 ms 14444 KB Output is correct
28 Correct 10 ms 14444 KB Output is correct
29 Correct 10 ms 14444 KB Output is correct
30 Correct 10 ms 14444 KB Output is correct
31 Correct 10 ms 14444 KB Output is correct
32 Correct 14 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 11 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 10 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 10 ms 14444 KB Output is correct
42 Correct 12 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 12 ms 14828 KB Output is correct
53 Correct 12 ms 14828 KB Output is correct
54 Correct 12 ms 14700 KB Output is correct
55 Correct 11 ms 14700 KB Output is correct
56 Correct 12 ms 14700 KB Output is correct
57 Correct 13 ms 14700 KB Output is correct
58 Correct 15 ms 14700 KB Output is correct
59 Correct 12 ms 14700 KB Output is correct
60 Correct 11 ms 14700 KB Output is correct
61 Correct 13 ms 15212 KB Output is correct
62 Correct 13 ms 15212 KB Output is correct
63 Correct 12 ms 14700 KB Output is correct
64 Correct 11 ms 14700 KB Output is correct
65 Correct 10 ms 14572 KB Output is correct
66 Correct 12 ms 14828 KB Output is correct
67 Correct 12 ms 14700 KB Output is correct
68 Correct 12 ms 14700 KB Output is correct
69 Correct 12 ms 14828 KB Output is correct
70 Correct 13 ms 14700 KB Output is correct
# 결과 실행 시간 메모리 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 10 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 11 ms 14444 KB Output is correct
12 Correct 10 ms 14444 KB Output is correct
13 Correct 10 ms 14452 KB Output is correct
14 Correct 10 ms 14444 KB Output is correct
15 Correct 10 ms 14444 KB Output is correct
16 Correct 11 ms 14444 KB Output is correct
17 Correct 11 ms 14444 KB Output is correct
18 Correct 10 ms 14444 KB Output is correct
19 Correct 11 ms 14444 KB Output is correct
20 Correct 10 ms 14444 KB Output is correct
21 Correct 11 ms 14444 KB Output is correct
22 Correct 11 ms 14444 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 10 ms 14444 KB Output is correct
27 Correct 10 ms 14444 KB Output is correct
28 Correct 10 ms 14444 KB Output is correct
29 Correct 10 ms 14444 KB Output is correct
30 Correct 10 ms 14444 KB Output is correct
31 Correct 10 ms 14444 KB Output is correct
32 Correct 14 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 11 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 10 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 10 ms 14444 KB Output is correct
42 Correct 12 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 12 ms 14828 KB Output is correct
53 Correct 12 ms 14828 KB Output is correct
54 Correct 12 ms 14700 KB Output is correct
55 Correct 11 ms 14700 KB Output is correct
56 Correct 12 ms 14700 KB Output is correct
57 Correct 13 ms 14700 KB Output is correct
58 Correct 15 ms 14700 KB Output is correct
59 Correct 12 ms 14700 KB Output is correct
60 Correct 11 ms 14700 KB Output is correct
61 Correct 13 ms 15212 KB Output is correct
62 Correct 13 ms 15212 KB Output is correct
63 Correct 12 ms 14700 KB Output is correct
64 Correct 11 ms 14700 KB Output is correct
65 Correct 10 ms 14572 KB Output is correct
66 Correct 12 ms 14828 KB Output is correct
67 Correct 12 ms 14700 KB Output is correct
68 Correct 12 ms 14700 KB Output is correct
69 Correct 12 ms 14828 KB Output is correct
70 Correct 13 ms 14700 KB Output is correct
71 Correct 40 ms 18480 KB Output is correct
72 Correct 39 ms 17896 KB Output is correct
73 Correct 25 ms 17132 KB Output is correct
74 Correct 46 ms 21868 KB Output is correct
75 Correct 44 ms 20588 KB Output is correct
76 Correct 386 ms 63852 KB Output is correct
77 Correct 369 ms 43628 KB Output is correct
78 Correct 234 ms 31456 KB Output is correct
79 Correct 308 ms 51504 KB Output is correct
80 Correct 334 ms 41324 KB Output is correct
81 Correct 37 ms 18608 KB Output is correct
82 Correct 34 ms 17896 KB Output is correct
83 Correct 28 ms 17260 KB Output is correct
84 Correct 48 ms 21484 KB Output is correct
85 Correct 42 ms 20460 KB Output is correct
86 Correct 330 ms 57948 KB Output is correct
87 Correct 308 ms 57692 KB Output is correct
88 Correct 187 ms 31328 KB Output is correct
89 Correct 318 ms 49872 KB Output is correct
90 Correct 327 ms 41708 KB Output is correct