#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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9820 KB |
Output is correct |
2 |
Correct |
37 ms |
10004 KB |
Output is correct |
3 |
Correct |
49 ms |
10012 KB |
Output is correct |
4 |
Correct |
65 ms |
10076 KB |
Output is correct |
5 |
Correct |
44 ms |
9816 KB |
Output is correct |
6 |
Correct |
100 ms |
10484 KB |
Output is correct |
7 |
Correct |
61 ms |
10076 KB |
Output is correct |
8 |
Correct |
39 ms |
9816 KB |
Output is correct |
9 |
Correct |
50 ms |
9820 KB |
Output is correct |
10 |
Correct |
44 ms |
10076 KB |
Output is correct |
11 |
Correct |
46 ms |
9816 KB |
Output is correct |
12 |
Correct |
36 ms |
10028 KB |
Output is correct |
13 |
Correct |
100 ms |
10076 KB |
Output is correct |
14 |
Correct |
54 ms |
10840 KB |
Output is correct |
15 |
Correct |
58 ms |
10744 KB |
Output is correct |
16 |
Correct |
32 ms |
9820 KB |
Output is correct |
17 |
Correct |
65 ms |
12628 KB |
Output is correct |
18 |
Correct |
60 ms |
11036 KB |
Output is correct |
19 |
Correct |
45 ms |
10072 KB |
Output is correct |
20 |
Correct |
223 ms |
10168 KB |
Output is correct |
21 |
Correct |
79 ms |
10188 KB |
Output is correct |
22 |
Correct |
50 ms |
10236 KB |
Output is correct |
23 |
Correct |
50 ms |
9820 KB |
Output is correct |
24 |
Correct |
54 ms |
9820 KB |
Output is correct |
25 |
Correct |
47 ms |
9816 KB |
Output is correct |
26 |
Correct |
37 ms |
9816 KB |
Output is correct |
27 |
Correct |
170 ms |
10076 KB |
Output is correct |
28 |
Correct |
133 ms |
12572 KB |
Output is correct |
29 |
Correct |
65 ms |
10772 KB |
Output is correct |
30 |
Correct |
27 ms |
9820 KB |
Output is correct |
31 |
Correct |
118 ms |
12848 KB |
Output is correct |
32 |
Correct |
79 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2071 ms |
17640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2037 ms |
21180 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9820 KB |
Output is correct |
2 |
Correct |
37 ms |
10004 KB |
Output is correct |
3 |
Correct |
49 ms |
10012 KB |
Output is correct |
4 |
Correct |
65 ms |
10076 KB |
Output is correct |
5 |
Correct |
44 ms |
9816 KB |
Output is correct |
6 |
Correct |
100 ms |
10484 KB |
Output is correct |
7 |
Correct |
61 ms |
10076 KB |
Output is correct |
8 |
Correct |
39 ms |
9816 KB |
Output is correct |
9 |
Correct |
50 ms |
9820 KB |
Output is correct |
10 |
Correct |
44 ms |
10076 KB |
Output is correct |
11 |
Correct |
46 ms |
9816 KB |
Output is correct |
12 |
Correct |
36 ms |
10028 KB |
Output is correct |
13 |
Correct |
100 ms |
10076 KB |
Output is correct |
14 |
Correct |
54 ms |
10840 KB |
Output is correct |
15 |
Correct |
58 ms |
10744 KB |
Output is correct |
16 |
Correct |
32 ms |
9820 KB |
Output is correct |
17 |
Correct |
65 ms |
12628 KB |
Output is correct |
18 |
Correct |
60 ms |
11036 KB |
Output is correct |
19 |
Correct |
45 ms |
10072 KB |
Output is correct |
20 |
Correct |
223 ms |
10168 KB |
Output is correct |
21 |
Correct |
79 ms |
10188 KB |
Output is correct |
22 |
Correct |
50 ms |
10236 KB |
Output is correct |
23 |
Correct |
50 ms |
9820 KB |
Output is correct |
24 |
Correct |
54 ms |
9820 KB |
Output is correct |
25 |
Correct |
47 ms |
9816 KB |
Output is correct |
26 |
Correct |
37 ms |
9816 KB |
Output is correct |
27 |
Correct |
170 ms |
10076 KB |
Output is correct |
28 |
Correct |
133 ms |
12572 KB |
Output is correct |
29 |
Correct |
65 ms |
10772 KB |
Output is correct |
30 |
Correct |
27 ms |
9820 KB |
Output is correct |
31 |
Correct |
118 ms |
12848 KB |
Output is correct |
32 |
Correct |
79 ms |
10844 KB |
Output is correct |
33 |
Execution timed out |
2071 ms |
17640 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |