这个题有点难!
先贴份代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
//typedef long long ll;
typedef pair<int,int> pii;
#define x first
#define y second
#define pb push_back
#define inf 1e18
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fer(i,a,b) for(int i=a;i<=b;i++)
#define der(i,a,b) for(int i=a;i>=b;i--)
const int maxn=1e5+10;
const int mod=1e9+7;
/*ll qsm(int a,int b)
{ll res=1; while(b){ if(b&1) res=res*a%mod; a=a*a%mod; b>>=1; } return res;}
*/
const int N=2e5+100;
int dr[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int n,k;
int m;
vector<int>g[N];
int dp[N][45];
int a[N];
int ans[N];
void dfs1(int u,int fa)
{
dp[u][0]=a[u];
for(int v:g[u])
{
if(v==fa)continue;
dfs1(v,u);
dp[u][0]^=dp[v][2*k-1];
fer(i,1,2*k-1)dp[u][i]^=dp[v][i-1];
}
}
void dfs2(int u,int fa)
{
fer(i,k,2*k-1)ans[u]^=dp[u][i];
for(auto v:g[u])
{
if(v==fa)continue;
dp[u][0]^=dp[v][2*k-1];
fer(i,1,2*k-1)dp[u][i]^=dp[v][i-1];
dp[v][0]^=dp[u][2*k-1];
fer(i,1,2*k-1)dp[v][i]^=dp[u][i-1];
dfs2(v,u);
dp[v][0]^=dp[u][2*k-1];
fer(i,1,2*k-1)dp[v][i]^=dp[u][i-1];
dp[u][0]^=dp[v][2*k-1];
fer(i,1,2*k-1)dp[u][i]^=dp[v][i-1];
}
}
void solve()
{
cin>>n>>k;
fer(i,1,n-1)
{
int a,b;
cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
fer(i,1,n)cin>>a[i];
dfs1(1,0);
dfs2(1,0);
// fer(i,1,n)cout<<ans[i]<<endl;
fer(i,1,n)cout<<(ans[i]>0)<<" ";
cout<<endl;
}
signed main()
{
IOS;
int _=1;
//cin>>_;
while(_--) solve();
return 0;
}