#include "bits/stdc++.h"
using namespace std;
const int N=2000;
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';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
70 ms |
620 KB |
Output is correct |
3 |
Correct |
55 ms |
620 KB |
Output is correct |
4 |
Correct |
98 ms |
748 KB |
Output is correct |
5 |
Runtime error |
3 ms |
780 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
70 ms |
620 KB |
Output is correct |
3 |
Correct |
55 ms |
620 KB |
Output is correct |
4 |
Correct |
98 ms |
748 KB |
Output is correct |
5 |
Runtime error |
3 ms |
780 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |