标签:
首先随便找一条路,然后找环啊,判断环,用线性基啊
#include<iostream> #include<cstdio> #include<cstring> #include<cstdio> #include<cmath> #include<string> #include<algorithm> #include<queue> #include<vector> #include<set> #include<stack> #include<map> using namespace std; long long n,m,cnt; vector<long long> w[250005]; vector<long long> e[250005]; bool vis[250005]; long long a[250005],ins[66],d[250005]; void dfs(int x) { vis[x]=1; for(int i=0;i<e[x].size();i++) { int v=e[x][i]; if(!vis[v]) d[v]=d[x]^w[x][i],dfs(v); else a[++cnt]=d[v]^w[x][i]^d[x]; } } void solve() { for(int i=1;i<=cnt;i++) { for(int j=63;j>=0;j--) { if((a[i]>>j)&1) { if(!ins[j]) { ins[j]=a[i]; break; } else a[i]^=ins[j]; } } } long long ans=d[n]; for(int i=63;i>=0;i--) if((ans^ins[i])>ans) ans=(ans^ins[i]); printf("%lld\n",ans); } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { long long x,y,z; scanf("%lld%lld%lld",&x,&y,&z); e[x].push_back(y); e[y].push_back(x); w[x].push_back(z); w[y].push_back(z); } dfs(1); solve(); return 0; }
标签:
原文地址:http://www.cnblogs.com/water-full/p/4501605.html