Submission #883172

#TimeUsernameProblemLanguageResultExecution timeMemory
883172NotLinuxUnique Cities (JOI19_ho_t5)C++17
4 / 100
2071 ms21180 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...