#include <bits/stdc++.h>
using namespace std;
int n,k;
vector<int> G[1000005];
int c[1000005];
int low[1000005];
int num[1000005];
int p[1000005];
int ct = 0;
int pa[500005];
int eg[500005];
int rk[500005];
void init(int n){
for (int i = 1; i <= n; i++){
pa[i] = i; rk[i] = 0;
eg[i] = 0;
}
}
int fin(int x){
return pa[x] == x ? x : pa[x] = fin(pa[x]);
}
void un(int x, int y){
x = fin(x), y = fin(y);
if (x == y) return;
if (rk[x] < rk[y]) swap(x,y);
pa[y] = x;
eg[x] += eg[y];
if (rk[x] == rk[y]) rk[x]++;
}
void dfs(int u){
num[u] = low[u] = ct++;
sz[u] = 1;
for (auto v : G[u]){
if (num[v] == -1){
p[v] = u;
//printf("%d -> %d\n",u,v);
dfs(v);
if (u <= n && v <= n){
if (low[v] <= num[u]){
un(u,v);
}
else{
eg[fin(u)]++;
eg[fin(v)]++;
}
//printf("%d %d\n",u,v);
}
low[u] = min(low[v], low[u]);
}
else if (v != p[u]){
low[u] = min(num[v], low[u]);
}
}
}
int main(){
scanf("%d%d",&n,&k);
for (int i = 1; i < n; i++){
int a,b;
scanf("%d%d",&a,&b);
G[a].push_back(b);
G[b].push_back(a);
}
for (int i = 1; i <= n; i++){
scanf("%d",&c[i]);
G[i].push_back(n+c[i]);
G[n+c[i]].push_back(i);
}
memset(low,-1,sizeof(low));
memset(num,-1,sizeof(num));
init(n);
dfs(1);
int ans = 0;
for (int i = 1; i <= n; i++){
if (i == pa[i] && eg[i] == 1) {
printf("%d ",i);
ans++;
}
}
printf("%d",(ans+1)/2);
}
Compilation message
mergers.cpp: In function 'void dfs(int)':
mergers.cpp:33:5: error: 'sz' was not declared in this scope
33 | sz[u] = 1;
| ^~
mergers.cpp: In function 'int main()':
mergers.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
mergers.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | scanf("%d%d",&a,&b);
| ~~~~~^~~~~~~~~~~~~~
mergers.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | scanf("%d",&c[i]);
| ~~~~~^~~~~~~~~~~~