比赛 NOI2015Day1 评测结果 AEEEEEEEEE
题目名称 程序自动分析 最终得分 10
用户昵称 甘罗 运行时间 0.006 s
代码语言 Pascal 内存使用 0.20 MiB
提交时间 2015-08-01 12:31:16
显示代码纯文本
program zht;
var
i,j,e,t,n,g,h:longint;
z:array[1..100,1..100] of longint;
ans:string;
procedure cz;
var
q:longint;
begin
 for q:=1 to 100 do
 begin
 if z[j,q]>0 then if z[i,q]=0 then begin z[i,q]:=z[j,q];z[q,i]:=z[j,q];end;
 if z[j,q]>0 then if z[i,q]<>z[j,q] then ans:='NO';
 end;
 for q:=1 to 100 do
 begin
 if z[i,q]>0 then if z[j,q]=0 then begin z[j,q]:=z[i,q];z[q,j]:=z[i,q];end;
 if z[i,q]>0 then if z[j,q]<>z[j,q] then ans:='NO';
 end;
end;


 procedure zc;
 var
 w:longint;
 begin
 for w:=1 to 100 do
  begin
  if z[i,w]=1 then if z[j,w]=0 then begin z[j,w]:=2;z[w,j]:=2;end;
  if z[i,w]=1 then if z[j,w]=1 then ans:='NO';

  end;
  for w:=1 to 100 do
  begin
  if z[j,w]=1 then if z[i,w]=0 then begin z[i,w]:=2;z[w,i]:=2;end;
  if z[j,w]=1 then if z[i,w]=1 then ans:='NO';

  end;
 end;


begin
assign(input,'prog.in');
assign(output,'prog.out');
reset(input);
rewrite(output);
readln(t);
 for g:=1 to t do
 begin
 readln(n);
 ans:='YES';
  for h:=1 to n do
    begin
    readln(i,j,e);
    if e=1 then if z[i,j]=0 then begin z[i,j]:=1;z[j,i]:=1;cz;end;
    if e=1 then if z[i,j]=2 then begin ans:='NO'; break;end;
    if e=0 then if z[i,j]=0 then begin z[i,j]:=2;z[j,i]:=2;zc;end;
    if e=0 then if z[i,j]=1 then begin ans:='NO'; break;end;
    end;
 writeln(ans);
 end;
 close(input);
close(output);
 end.