标签:smd rt4 gpu ec2 swp seo boolean dad vbo
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 71707 | Accepted: 21240 |
Description
Input
Output
Sample Input
100 7 1 101 1 2 1 2 2 2 3 2 3 3 1 1 3 2 3 1 1 5 5
Sample Output
3
Source
下面是神奇的接链子,还有取模性质的运用
待续……
1 program foodchain; 2 var 3 n,k,i,x,a,b,ans:longint; 4 uset,rel:array[0..50000] of longint; 5 6 function find(app:longint):longint; 7 var 8 t:longint; 9 begin 10 if uset[app]=0 then exit(app); 11 t:=find(uset[app]); 12 rel[app]:=(rel[app]+rel[uset[app]]) mod 3; 13 uset[app]:=t; 14 find:=uset[app]; 15 end; 16 17 function union(a,b:longint):boolean; 18 var 19 p1,p2:longint; 20 21 begin 22 p1:=find(a); 23 p2:=find(b); 24 if p1=p2 then //之前已经存在关系 25 if (rel[b]-rel[a]+3) mod 3<>x-1 then exit(false) 26 else exit(true); 27 28 uset[p2]:=p1; 29 rel[p2]:=(rel[a]+3-rel[b]+x-1) mod 3; 30 exit(true); 31 end; 32 33 begin 34 readln(n,k); 35 36 for i:= 1 to k do 37 begin 38 readln(x,a,b); 39 if (a>n) or (b>n) or ((x=2) and (a=b)) then inc(ans) 40 else if union(a,b)=false then inc(ans); 41 end; 42 43 writeln(ans); 44 end.
NOI 2001 & luogu P2024 & POJ 1182食物链
标签:smd rt4 gpu ec2 swp seo boolean dad vbo
原文地址:http://www.cnblogs.com/tonylim/p/6891708.html