BZOJ 1603 Usaco2008 Oct 打谷机 DFS

题目大意:给定一棵树,每个点是一个齿轮,,1号齿轮顺时针旋转,每条边有同向和反向两种连接方式,求n号齿轮的旋转方向 DFS一遍即可

;struct abcd{int to,f,next;}table[M<<1];int head[M],tot;int n,f[M];void Add(int x,int y,int z){table[++tot].to=y;table[tot].f=z;table[tot].next=head[x];head[x]=tot;}void DFS(int x,int from){int i;for(i=head[x];i;i=table[i].next)if(table[i].to!=from){f[table[i].to]=f[x]^table[i].f;DFS(table[i].to,x);}}int main(){int i,x,y,z;cin>>n;for(i=1;i<n;i++){scanf(“%d%d%d”,&x,&y,&z);Add(x,y,z);Add(y,x,z);}DFS(1,0);cout<<f[n]<<endl;return 0;}

世上没有绝望的处境,只有对处境绝望的人。

BZOJ 1603 Usaco2008 Oct 打谷机 DFS

相关文章:

你感兴趣的文章:

标签云: