Title: http://www.lydsy.com/JudgeOnline/problem.php?id=2337
Because it is XOR, we can get a bitwise deal if the weights (w& (1<<i)), then ex[u]+=1/d[u]* (1-f[v]), otherwise ex[u]+=1/d[u]*f[v], then Gaussian elimination.
Pay attention to a few points, the end of the side even out of all without consideration, do not have to judge the weight of the w>0 situation, so that a[n][n]=1, there are heavy edges do not die open adjacency matrix.
#include<cstring>#include<cstdio>#include<algorithm>#include<cmath>#include<iostream>#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineDown (i,l,r) for (int i=l;i>=r;i--)#defineCLR (x, y) memset (x,y,sizeof (×))#defineMAXN 210#definell Long Long#defineEPS 1e-6using namespacestd;structdata{intObj,pre,c;} e[200500];intD[MAXN],BIN[MAXN],HEAD[MAXN];DoubleA[maxn][maxn],ans;intN,x,y,z,m,tot;voidInsertintXintYintz) {D[x]++; E[++tot].obj=y; E[TOT].PRE=HEAD[X]; E[tot].c=z; head[x]=tot;} ll read () {ll x=0, f=1;CharCh=GetChar (); while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}voidSolveintN) { intNowDoubleT; Rep (I,1, N) { Now=i; while(Fabs (A[now][i]) <=eps) now++; if(now>n)Continue; if(Now!=i) Rep (J,1, n+1) Swap (a[i][j],a[now][j]); T=A[i][i]; Rep (J,1, n+1) a[i][j]/=T; Rep (J,1, N)if(j!=i) {T=A[j][i]; Rep (K,1, n+1) a[j][k]-=t*A[i][k]; } }}intMain () {bin[0]=1; Rep (I,1, -) bin[i]=bin[i-1]*2; N=read (); m=read (); Rep (I,1, M) { intx, Y, Z X=read (); Y=read (); z=read (); Insert (x, y, z); if(x!=y) Insert (y,x,z); } ans=0; Rep (O,0, -) {clr (A,0); Rep (U,1, N-1) {A[u][u]=1.0; for(intj=head[u];j;j=e[j].pre) { intv=E[j].obj; if(E[j].c&bin[o]) a[u][n+1]+=1.0/d[u],a[u][v]+=1.0/D[u]; Elsea[u][v]-=1.0/D[u]; }} A[n][n]=1.0; Solve (n); Ans+=a[1][n+1]*Bin[o]; } printf ("%.3lf\n", ans); return 0;}
bzoj2337: [Hnoi2011]xor and path