Solution:
- 看得题解
(逃,我太菜了,想不出这种做法 - 那么丢个链接
Attention:
- 板子别写错了
又写错了这次 - (long long)是左移63位,多了会溢出就会出鬼
Code:
//It is coded by Ning_Mew on 5.29
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=5e4+7,maxm=1e5+7;
int n,m;
LL x[70],sum[maxn],ans;
struct Edge{
int nxt,to;LL dis;
}edge[maxm*2];
int head[maxn],cnt=0;
bool vis[maxn];
void add(int from,int to,LL dis){
edge[++cnt].nxt=head[from]; edge[cnt].dis=dis;
edge[cnt].to=to; head[from]=cnt;
}
void push(LL ss){
for(int i=63;i>=0;i--){
if((ss>>i)&1){
if(!x[i]){x[i]=ss;return;}
else{ss=(ss^x[i]);}
}
}
}
void dfs(int u){
vis[u]=1;
for(int i=head[u];i!=0;i=edge[i].nxt){
int v=edge[i].to;
if(vis[v]){
push( ((sum[u]^edge[i].dis)^sum[v]) );
continue;
}else{
sum[v]=(sum[u]^edge[i].dis);
dfs(v);
}
}
}
int main(){
freopen("in.in","r",stdin);
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int x,y;LL z;scanf("%d%d%lld",&x,&y,&z);
add(x,y,z);add(y,x,z);
}
memset(vis,false,sizeof(vis));
dfs(1);
ans=sum[n];
for(int i=63;i>=0;i--){
if((ans^x[i])>ans)ans=(ans^x[i]);
}
printf("%lld
",ans);
return 0;
}
博主蒟蒻,随意转载。但必须附上原文链接:http://www.cnblogs.com/Ning-Mew/,否则你会终生找不到妹子!!!