Find a path + linear base.
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#defineMAXV 100050#defineMaxe 400500using namespacestd;structedge{Long LongV,W,NXT;} E[maxe];Long LongN,m,x,y,z,g[maxv],nume=0, dis[maxv],a[maxe],cnt=0, ins[ -];BOOLVIS[MAXV];voidAddedge (Long LongULong LongVLong LongW) {e[++nume].v=v; E[NUME].W=W; E[NUME].NXT=G[u]; G[u]=Nume;}voidDfsLong Longx) { for(Long LongI=g[x];i;i=e[i].nxt) { Long Longv=e[i].v; if(!Vis[v]) {Dis[v]=dis[x]^E[I].W; VIS[V]=true; DFS (v); } Elsea[++cnt]=dis[x]^dis[v]^E[I].W; }}voidGet_ins () { for(Long LongI=1; i<=cnt;i++) { for(Long Longj= the; j>=0; j--) { if((A[I]>>J) &1) { if(!Ins[j]) {Ins[j]=A[i]; Break; } Elsea[i]^=Ins[j]; } } }}intMain () {scanf ("%lld%lld",&n,&m); for(Long LongI=1; i<=m;i++) {scanf ("%lld%lld%lld",&x,&y,&z); Addedge (x, y, z); Addedge (Y,X,Z); } DFS (1); Get_ins (); Long Longans=Dis[n]; for(Long LongI= the; i>=0; i--) { if((Ans^ins[i]) >ans) ans^=Ins[i]; } printf ("%lld\n", ans); return 0; }
Bzoj 2115 Xor