标签:
1 var 2 i,j,k,l,m,n,x,y,z,vx,vi:longint; 3 c,a:array[0..10000] of longint; 4 flag:boolean; 5 function getfat(k:longint):longint; 6 var a1:longint; 7 begin 8 if k=c[k] then exit(k); 9 a1:=getfat(c[k]); 10 inc(a[k],a[c[k]]); 11 c[k]:=a1; 12 exit(c[k]); 13 end; 14 procedure doit(x,y,z:longint); 15 var a1,a2,a3,a4,a5,a6:longint; 16 begin 17 a1:=getfat(x);a2:=getfat(y); 18 a3:=a[x];a4:=a[y]; 19 if a1<>a2 then 20 begin 21 c[a1]:=a2; 22 a[a1]:=a4-a3-z; 23 end 24 else if (a4-a3)<>z then flag:=false; 25 end; 26 begin 27 readln(vx); 28 for vi:=1 to vx do 29 begin 30 31 fillchar(c,sizeof(c),0); 32 fillchar(a,sizeof(a),0); 33 readln(n,m); 34 for i:=0 to n do c[i]:=i; 35 flag:=true; 36 for i:=1 to m do 37 begin 38 readln(x,y,z); 39 doit(x-1,y,z); 40 end; 41 if flag then writeln(‘true‘) else writeln(‘false‘); 42 43 end; 44 end. 45
标签:
原文地址:http://www.cnblogs.com/HansBug/p/4174918.html