#21TLE 玄关求条
查看原帖
#21TLE 玄关求条
1238374
untitled_cpp楼主2025/8/5 12:27
#include<bits/stdc++.h>
using namespace std;
//#define Inc
#ifdef Inc
#include<bits/extc++.h>
#include<windows.h>
#endif
#define Define
#ifdef Define
#define up(_name_,_leftbound_,_rightbound_) for(auto _name_=(_leftbound_);(_name_)<=(_rightbound_);++(_name_))
#define dn(_name_,_leftbound_,_rightbound_) for(auto _name_=(_leftbound_);(_name_)>=(_rightbound_);--(_name_))
#define DEBUG cerr<<"---DEBUG---\n"<<__LINE__<<"\n-----------\n"
#define ll long long
#define ull unsigned long long
#define un unsigned
#define il inline
#define re register
#define i128 __int128
#define endl '\n'
#define db double
#define ld long double
#define gc (p1==p2&&(p2=(p1=in)+fread(in,1,1<<20,stdin),p1==p2)?EOF:*p1++)
#define Log(_shang_,_xia_) (log(_shang_)/log(_xia_))
#define _1st first
#define _2nd second
#define mkp(_firstone_,_secondone_) (make_pair((_firstone_),(_secondone_)))
#define pb(_Num_) push_back(_Num_)
constexpr int inf = (1 << 30);
constexpr int mod = (998244353);
#endif
#define int unsigned long long
int n,m;
const int N=500005;
int head[N],cnt=0;
struct Edge{
	int to,w,nxt;
}e[N<<1];
void addEdge(int u,int v,int w){
	e[++cnt]={v,w,head[u]};
	head[u]=cnt;
}
int sum[N];
void dfs(int x,int from){
	for(int i=head[x];i;i=e[i].nxt){
		int to=e[i].to;
		if(to==from) continue;
		sum[to]=sum[x]^e[i].w;
		dfs(to,x);
	}
}
signed main(int argc,char *argv[]){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	up(i,1,n-1){
		int x,y,z;
		cin>>x>>y>>z;
		addEdge(x,y,z);
		addEdge(y,x,z);
	}
	dfs(1,0);
	for(int i=1;i<=m;i++){
		int x,y,z;
		cin>>x>>y>>z;
		if((sum[x]^sum[y])==z) cout<<"YeS"<<endl;
		else cout<<"nO"<<endl;
	}
	return 0;
}
/*
---INFORMATIONS---
TIME:2025/8/5 11:47:18
PROBLEM:P8200
CODE BY __CrossBow_EXE__ Luogu uid967841
CEXE好闪,拜谢CEXE。
*/

找到问题去私信@CrossBow_EXE 领取关注()

2025/8/5 12:27
加载中...