标签:
【数据范围】
对于30%的数据,保证N < =1000
对于100%的数据,保证N < =1000000
题解:此题一拿到,不难发现是一个比较明显的二分图匹配,可是如phile神犇所言(orzPhile2333),匈牙利算法的时间复杂度为O(NM),可是此题中实际上N<=10000 M<=1000000,这不是必死无疑的节奏么——可是貌似裸的匈牙利算法还是妥妥Accept了。。。so神奇。。。求高人解释
1 /************************************************************** 2 Problem: 1854 3 User: HansBug 4 Language: Pascal 5 Result: Accepted 6 Time:3396 ms 7 Memory:43248 kb 8 ****************************************************************/ 9 10 type 11 point=^node; 12 node=record 13 g:longint; 14 next:point; 15 end; 16 17 var 18 i,j,k,l,m,n,pt:longint; 19 c,f:array[0..1000500] of longint; 20 a:array[0..1000500] of point; 21 function min(x,y:longint):longint;inline; 22 begin 23 if x<y then min:=x else min:=y; 24 end; 25 procedure add(x,y:longint);inline; 26 var p:point; 27 begin 28 new(p); 29 p^.g:=y; 30 p^.next:=a[x]; 31 a[x]:=p; 32 end; 33 function check(x:longint):boolean;inline; 34 var p:point; 35 begin 36 p:=a[x]; 37 while p<>nil do 38 begin 39 if f[p^.g]<>pt then 40 begin 41 f[p^.g]:=pt; 42 if c[p^.g]=0 then 43 begin 44 c[p^.g]:=x; 45 exit(true); 46 end 47 else if check(c[p^.g]) then 48 begin 49 c[p^.g]:=x; 50 exit(true); 51 end; 52 end; 53 p:=p^.next; 54 end; 55 exit(false); 56 end; 57 begin 58 readln(n); 59 for i:=1 to n do a[i]:=nil; 60 for i:=1 to n do 61 begin 62 readln(j,k); 63 add(j,i);add(k,i); 64 end; 65 fillchar(c,sizeof(c),0); 66 fillchar(f,sizeof(f),0); 67 pt:=0; 68 for i:=1 to 10000 do 69 begin 70 inc(pt); 71 if not(check(i)) then 72 begin 73 writeln(i-1); 74 halt; 75 end; 76 end; 77 writeln(10000); 78 end.
标签:
原文地址:http://www.cnblogs.com/HansBug/p/4230549.html