This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |