#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#define int unsigned long long
using namespace std;
signed main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m;cin>>n>>m;
vector<vector<pair<int,int>>>g(n+10);
vector<int>f(n+10,0);
for(int i=1,a,b,w;i<n;i++)
{
cin>>a>>b>>w;
g[a].push_back({b,w});
g[b].push_back({a,w});
}
function<void(int u,int fa)> dfs = [&](int u,int fa)
{
for(auto [v,w] : g[u])
{
if(v==fa)continue;
f[v]=f[u]^w;
dfs(v,u);
}
};
dfs(1,-1);
while(m--)
{
int a,b,k;
cin>>a>>b>>k;
if((f[a]^f[b])==k)cout<<"Yes"<<'\n';
else cout<<"No"<<'\n';
}
}
|