没什么好说的了,用CL2姐姐的话说,题解满天飞,标程也满天飞……
我的代码:
Program eat;//by_Thispoet Const maxn=50005; Var father,data :Array[1..maxn]of Longint; ans,i,k,n,m,p,q :Longint; Function Root(i:Longint):Longint; var t:Longint; begin if father[i]=i then exit(i); t:=father[i]; father[i]:=Root(father[i]); data[i]:=(data[i]+data[t])mod 3; exit(father[i]); end; BEGIN readln(n,m); ans:=0; for i:=1 to n do father[i]:=i; fillchar(data,sizeof(data),0); while m>0 do begin readln(k,p,q); if (p>n)or(q>n) then begin dec(m); inc(ans); continue; end;//pos 1 case k of 1: begin if Root(p)=Root(q) then begin if data[p]<>data[q] then inc(ans); end else begin i:=Root(p); father[i]:=q; data[i]:=(3-data[p])mod 3; end; end; 2: begin if Root(p)=Root(q) then begin i:=(data[p]-data[q]+3)mod 3; if i<>1 then inc(ans); end else begin i:=Root(p); father[i]:=q; data[i]:=(4-data[p])mod 3; end; end; end; dec(m); end; writeln(ans); END.