pku1274 The Perfect Stall

有n头牛,m个牛栏,其中每头牛都有自己愿意去的牛栏,求牛和牛栏的最大匹配。

简单的二分图裸题,居然调了1节课,数据会阴人啊!!

每行第一个数是说这一行接下来有多少个数,可是这些数完了这一行还有数,用read就悲催了!

View Code
 1 program pku1274(input,output);
2 var
3 f : array[0..301,0..301] of boolean;
4 v : array[0..301] of boolean;
5 lk : array[0..301] of longint;
6 n,m : longint;
7 procedure init;
8 var
9 i,j,x,y : longint;
10 begin
11 readln(n,m);
12 fillchar(f,sizeof(f),false);
13 fillchar(lk,sizeof(lk),0);
14 for i:=1 to n do
15 begin
16 read(x);
17 for j:=1 to x do
18 begin
19 read(y);
20 f[i,y]:=true;
21 end;
22 readln;//就在这里,你把这行删了就WA
23 end;
24 end; { init }
25 function find(now :longint ):boolean;
26 var
27 i : longint;
28 begin
29 for i:=1 to m do
30 if (f[now,i])and(not v[i]) then
31 begin
32 v[i]:=true;
33 if (lk[i]=0)or(find(lk[i])) then
34 begin
35 lk[i]:=now;
36 exit(true);
37 end;
38 end;
39 exit(false);
40 end; { find }
41 function main():longint;
42 var
43 i : longint;
44 begin
45 main:=0;
46 for i:=1 to n do
47 begin
48 fillchar(v,sizeof(v),false);
49 if find(i) then
50 inc(main);
51 end;
52 end; { main }
53 begin
54 while not eof do
55 begin
56 init;
57 writeln(main);
58 end;
59 end.



posted @ 2012-03-01 11:42  Codinginging  阅读(146)  评论(0编辑  收藏  举报