round4粗略地看了下。。2道数论我就不想做了(其实是要赶集地补作业)

权值并查集。。。做过食物链了再做感觉不乱了。。

然而爆0?输出调试没删掉真是日了狗了QAQ

还是先滚去搞初赛吧。。。再加上作业仍未补完= =

 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(i=l;i<=r;i++)
 3 #define dec(i,l,r) for(i=l;i>=r;i--)
 4 #define inf 1e9
 5 #define mem(a) memset(a,0,sizeof(a))
 6 #define ll long long
 7 #define succ(x) (1<<x)
 8 #define NM 5000
 9 using namespace std;
10 int read(){
11     int x=0,f=1;char ch=getchar();
12     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
13     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
14     return x*f;
15 }
16 int f[NM],a[NM],m,n,T,_x,_y,v,i,flag,fx,fy,b[NM];
17 int find(int x){
18     if(f[x]==x)return x;
19     int t=f[x];
20     f[x]=find(f[x]);
21     a[x]=a[x]+a[t]-b[x];
22     b[x]=a[f[x]];
23     return f[x];
24 }
25 int main(){
26     T=read();
27     while(T--){
28         mem(a);mem(f);flag=false;
29         n=read();m=read();
30         inc(i,1,n)f[i]=i;
31         inc(i,1,m){
32             _x=read();_y=read();v=read();
33             if(find(_x)==find(_y)){
34                 if(a[_y]-a[_x]!=v)flag=true;
35             }else{
36                 fx=find(_x);fy=find(_y);
37                 f[fx]=fy;b[fx]=a[fy];a[fx]=a[fx]+a[_y]-v-a[_x];
38             }
39 //            if(flag)printf("Bessie is blind.\n");
40 //            else printf("Bessie's eyes are good\n");
41         }
42         if(flag)printf("Bessie is blind.\n");
43         else printf("Bessie's eyes are good\n");
44     }
45     return 0;
46 }
View Code

 

posted on 2015-10-06 18:33  onlyRP  阅读(193)  评论(0编辑  收藏  举报