Submission #883127

# Submission time Handle Problem Language Result Execution time Memory
883127 2023-12-04T15:16:31 Z vjudge1 Unique Cities (JOI19_ho_t5) C++17
4 / 100
2000 ms 21052 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n , m , c[N];
vector < int > tree[N];
vector < int > dist[N];
void dfs(int node , int par , int dst){
	dist[dst].push_back(node);
	for(auto itr : tree[node]){
		if(itr != par){
			dfs(itr,node,dst+1);
		}
	}
}
void solve(){
	cin >> n >> m;
	for(int i = 1;i<n;i++){
		int a,b;
		cin >> a >> b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	for(int i = 1;i<=n;i++){
		cin >> c[i];
	}
	for(int i = 1;i<=n;i++){
		for(int j = 1;j<=n;j++){
			dist[j].clear();
		}
		dfs(i,0,0);
		set < int > ans;
		for(int j = 1;j<=n;j++){
			if(dist[j].size() == 1){
				ans.insert(c[dist[j][0]]);
			}
		}
		cout << ans.size() << endl;
	}
}	
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9820 KB Output is correct
2 Correct 37 ms 9816 KB Output is correct
3 Correct 50 ms 9816 KB Output is correct
4 Correct 73 ms 10076 KB Output is correct
5 Correct 55 ms 9820 KB Output is correct
6 Correct 98 ms 10116 KB Output is correct
7 Correct 68 ms 10072 KB Output is correct
8 Correct 45 ms 10000 KB Output is correct
9 Correct 47 ms 9820 KB Output is correct
10 Correct 46 ms 10084 KB Output is correct
11 Correct 45 ms 9820 KB Output is correct
12 Correct 32 ms 9820 KB Output is correct
13 Correct 93 ms 10072 KB Output is correct
14 Correct 56 ms 10832 KB Output is correct
15 Correct 60 ms 10736 KB Output is correct
16 Correct 28 ms 9816 KB Output is correct
17 Correct 76 ms 12600 KB Output is correct
18 Correct 59 ms 11036 KB Output is correct
19 Correct 51 ms 10072 KB Output is correct
20 Correct 225 ms 10188 KB Output is correct
21 Correct 77 ms 10120 KB Output is correct
22 Correct 41 ms 9820 KB Output is correct
23 Correct 50 ms 9820 KB Output is correct
24 Correct 52 ms 10336 KB Output is correct
25 Correct 46 ms 9816 KB Output is correct
26 Correct 34 ms 9980 KB Output is correct
27 Correct 166 ms 10140 KB Output is correct
28 Correct 132 ms 12628 KB Output is correct
29 Correct 66 ms 10832 KB Output is correct
30 Correct 28 ms 9820 KB Output is correct
31 Correct 138 ms 12624 KB Output is correct
32 Correct 77 ms 10836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2015 ms 17620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2021 ms 21052 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9820 KB Output is correct
2 Correct 37 ms 9816 KB Output is correct
3 Correct 50 ms 9816 KB Output is correct
4 Correct 73 ms 10076 KB Output is correct
5 Correct 55 ms 9820 KB Output is correct
6 Correct 98 ms 10116 KB Output is correct
7 Correct 68 ms 10072 KB Output is correct
8 Correct 45 ms 10000 KB Output is correct
9 Correct 47 ms 9820 KB Output is correct
10 Correct 46 ms 10084 KB Output is correct
11 Correct 45 ms 9820 KB Output is correct
12 Correct 32 ms 9820 KB Output is correct
13 Correct 93 ms 10072 KB Output is correct
14 Correct 56 ms 10832 KB Output is correct
15 Correct 60 ms 10736 KB Output is correct
16 Correct 28 ms 9816 KB Output is correct
17 Correct 76 ms 12600 KB Output is correct
18 Correct 59 ms 11036 KB Output is correct
19 Correct 51 ms 10072 KB Output is correct
20 Correct 225 ms 10188 KB Output is correct
21 Correct 77 ms 10120 KB Output is correct
22 Correct 41 ms 9820 KB Output is correct
23 Correct 50 ms 9820 KB Output is correct
24 Correct 52 ms 10336 KB Output is correct
25 Correct 46 ms 9816 KB Output is correct
26 Correct 34 ms 9980 KB Output is correct
27 Correct 166 ms 10140 KB Output is correct
28 Correct 132 ms 12628 KB Output is correct
29 Correct 66 ms 10832 KB Output is correct
30 Correct 28 ms 9820 KB Output is correct
31 Correct 138 ms 12624 KB Output is correct
32 Correct 77 ms 10836 KB Output is correct
33 Execution timed out 2015 ms 17620 KB Time limit exceeded
34 Halted 0 ms 0 KB -