#include "bits/stdc++.h"
using namespace std;
const int N=2005;
int n,m;
vector<int> adj[N];
int c[N];
int dist[N];
vector<int> atD[N];
void dfs(int x, int pa){
for(int i : adj[x]){
if(i==pa) continue;
dist[i]=dist[x]+1;
atD[dist[i]].push_back(c[i]);
dfs(i,x);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin>>n>>m;
for(int i=0; i<n-1; i++){
int a,b; cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for(int i=1; i<=n; i++) cin>>c[i];
for(int i=1; i<=n; i++){
memset(dist,-1,sizeof(dist));
for(int j=0; j<=n; j++) atD[j].clear();
dist[i]=0;
dfs(i,-1);
unordered_set<int> uniq;
for(int j=1; j<=n; j++){
//if(i==2) cout<<dist[1]<<"HI"<<endl;
if(atD[j].size()!=1) continue;
uniq.insert(atD[j].back());
}
cout<<(uniq.size())<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
68 ms |
620 KB |
Output is correct |
3 |
Correct |
55 ms |
620 KB |
Output is correct |
4 |
Correct |
91 ms |
876 KB |
Output is correct |
5 |
Correct |
87 ms |
640 KB |
Output is correct |
6 |
Correct |
107 ms |
748 KB |
Output is correct |
7 |
Correct |
92 ms |
876 KB |
Output is correct |
8 |
Correct |
76 ms |
620 KB |
Output is correct |
9 |
Correct |
86 ms |
620 KB |
Output is correct |
10 |
Correct |
84 ms |
876 KB |
Output is correct |
11 |
Correct |
85 ms |
620 KB |
Output is correct |
12 |
Correct |
62 ms |
620 KB |
Output is correct |
13 |
Correct |
105 ms |
748 KB |
Output is correct |
14 |
Correct |
91 ms |
1536 KB |
Output is correct |
15 |
Correct |
91 ms |
1388 KB |
Output is correct |
16 |
Correct |
53 ms |
620 KB |
Output is correct |
17 |
Correct |
98 ms |
3308 KB |
Output is correct |
18 |
Correct |
87 ms |
1644 KB |
Output is correct |
19 |
Correct |
80 ms |
748 KB |
Output is correct |
20 |
Correct |
249 ms |
876 KB |
Output is correct |
21 |
Correct |
111 ms |
876 KB |
Output is correct |
22 |
Correct |
78 ms |
620 KB |
Output is correct |
23 |
Correct |
86 ms |
620 KB |
Output is correct |
24 |
Correct |
83 ms |
620 KB |
Output is correct |
25 |
Correct |
82 ms |
748 KB |
Output is correct |
26 |
Correct |
61 ms |
620 KB |
Output is correct |
27 |
Correct |
203 ms |
748 KB |
Output is correct |
28 |
Correct |
159 ms |
3268 KB |
Output is correct |
29 |
Correct |
100 ms |
1644 KB |
Output is correct |
30 |
Correct |
53 ms |
620 KB |
Output is correct |
31 |
Correct |
122 ms |
3436 KB |
Output is correct |
32 |
Correct |
108 ms |
1644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
68 ms |
620 KB |
Output is correct |
3 |
Correct |
55 ms |
620 KB |
Output is correct |
4 |
Correct |
91 ms |
876 KB |
Output is correct |
5 |
Correct |
87 ms |
640 KB |
Output is correct |
6 |
Correct |
107 ms |
748 KB |
Output is correct |
7 |
Correct |
92 ms |
876 KB |
Output is correct |
8 |
Correct |
76 ms |
620 KB |
Output is correct |
9 |
Correct |
86 ms |
620 KB |
Output is correct |
10 |
Correct |
84 ms |
876 KB |
Output is correct |
11 |
Correct |
85 ms |
620 KB |
Output is correct |
12 |
Correct |
62 ms |
620 KB |
Output is correct |
13 |
Correct |
105 ms |
748 KB |
Output is correct |
14 |
Correct |
91 ms |
1536 KB |
Output is correct |
15 |
Correct |
91 ms |
1388 KB |
Output is correct |
16 |
Correct |
53 ms |
620 KB |
Output is correct |
17 |
Correct |
98 ms |
3308 KB |
Output is correct |
18 |
Correct |
87 ms |
1644 KB |
Output is correct |
19 |
Correct |
80 ms |
748 KB |
Output is correct |
20 |
Correct |
249 ms |
876 KB |
Output is correct |
21 |
Correct |
111 ms |
876 KB |
Output is correct |
22 |
Correct |
78 ms |
620 KB |
Output is correct |
23 |
Correct |
86 ms |
620 KB |
Output is correct |
24 |
Correct |
83 ms |
620 KB |
Output is correct |
25 |
Correct |
82 ms |
748 KB |
Output is correct |
26 |
Correct |
61 ms |
620 KB |
Output is correct |
27 |
Correct |
203 ms |
748 KB |
Output is correct |
28 |
Correct |
159 ms |
3268 KB |
Output is correct |
29 |
Correct |
100 ms |
1644 KB |
Output is correct |
30 |
Correct |
53 ms |
620 KB |
Output is correct |
31 |
Correct |
122 ms |
3436 KB |
Output is correct |
32 |
Correct |
108 ms |
1644 KB |
Output is correct |
33 |
Runtime error |
1 ms |
748 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |