Submission #329959

# Submission time Handle Problem Language Result Execution time Memory
329959 2020-11-23T09:32:57 Z oolimry None (KOI18_family) C++14
44 / 100
27 ms 492 KB
#include <bits/stdc++.h>
using namespace std;

struct tree{
	int n, k, root;
	
	vector<int> child[305];
	vector<int> stuff[305];
	int vis[305];
	void init(){
		for(int i = 1;i <= n;i++){
			vis[i] = false;
		}
	}
	
	void dfs(int u){
		if(vis[u]) return;
		vis[u] = true;
		
		if(u <= k){
			stuff[u] = {u};
			return;
		}
		
		for(int v : child[u]){
			dfs(v);
			for(int x : stuff[v]) stuff[u].push_back(x);
		}
	}
	
} A, B;

bool overlap(vector<int> a, vector<int> b){
	if((int) a.size() > (int) b.size()) swap(a,b);
	
	int cnt = 0;;
	sort(b.begin(), b.end()); b.push_back(123283293);
	for(int x : a){
		if(*lower_bound(b.begin(), b.end(), x) == x) cnt++;
	}
	
	return (cnt == 0) || (cnt == (int) a.size());
}

int main(){
	int n1, n2, K; cin >> n1 >> n2 >> K;
	
	assert(n1 <= 300);
	A.n = n1, A.k = K;
	B.n = n2, B.k = K;
	
	for(int i = 1;i <= n1;i++){
		int a; cin >> a;
		A.child[a].push_back(i);
	}
	
	for(int i = 1;i <= n2;i++){
		int b; cin >> b;
		B.child[b].push_back(i);
	}
	
	for(int i = 1;i <= n1;i++) A.dfs(i);
	for(int i = 1;i <= n2;i++) B.dfs(i);
	
	for(int i = 1;i <= n1;i++){
		//for(int x : A.stuff[i]) cout << x << " "; cout << "\n";
		for(int j = 1;j <= n2;j++){
			if(!overlap(A.stuff[i], B.stuff[j])){
				cout << "NO";
				return 0;
			}
		}
	}
	cout << "YES";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 27 ms 364 KB Output is correct
15 Correct 13 ms 492 KB Output is correct
16 Correct 12 ms 364 KB Output is correct
17 Correct 5 ms 364 KB Output is correct
18 Correct 5 ms 364 KB Output is correct
19 Correct 4 ms 364 KB Output is correct
20 Correct 3 ms 364 KB Output is correct
21 Correct 7 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 27 ms 364 KB Output is correct
15 Correct 13 ms 492 KB Output is correct
16 Correct 12 ms 364 KB Output is correct
17 Correct 5 ms 364 KB Output is correct
18 Correct 5 ms 364 KB Output is correct
19 Correct 4 ms 364 KB Output is correct
20 Correct 3 ms 364 KB Output is correct
21 Correct 7 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 13 ms 364 KB Output is correct
37 Correct 4 ms 364 KB Output is correct
38 Correct 19 ms 364 KB Output is correct
39 Correct 26 ms 492 KB Output is correct
40 Correct 12 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 7 ms 364 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 15 ms 364 KB Output is correct
49 Correct 3 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 27 ms 364 KB Output is correct
15 Correct 13 ms 492 KB Output is correct
16 Correct 12 ms 364 KB Output is correct
17 Correct 5 ms 364 KB Output is correct
18 Correct 5 ms 364 KB Output is correct
19 Correct 4 ms 364 KB Output is correct
20 Correct 3 ms 364 KB Output is correct
21 Correct 7 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 13 ms 364 KB Output is correct
37 Correct 4 ms 364 KB Output is correct
38 Correct 19 ms 364 KB Output is correct
39 Correct 26 ms 492 KB Output is correct
40 Correct 12 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 7 ms 364 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 15 ms 364 KB Output is correct
49 Correct 3 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 27 ms 364 KB Output is correct
15 Correct 13 ms 492 KB Output is correct
16 Correct 12 ms 364 KB Output is correct
17 Correct 5 ms 364 KB Output is correct
18 Correct 5 ms 364 KB Output is correct
19 Correct 4 ms 364 KB Output is correct
20 Correct 3 ms 364 KB Output is correct
21 Correct 7 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 13 ms 364 KB Output is correct
37 Correct 4 ms 364 KB Output is correct
38 Correct 19 ms 364 KB Output is correct
39 Correct 26 ms 492 KB Output is correct
40 Correct 12 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 7 ms 364 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 15 ms 364 KB Output is correct
49 Correct 3 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
52 Halted 0 ms 0 KB -