pku1469 COURSES
这道题目就没有1274那么阴人,学生一边,课程一边,构造二分图,看最大匹配是否等于m就可以了
View Code
1 program pku1469(input,output);
2 var
3 f : array[0..101,0..301] of boolean;
4 lk : array[0..301] of longint;
5 v : array[0..301] of boolean;
6 n,m,p,k : longint;
7 procedure init;
8 var
9 i,j,x,y : longint;
10 begin
11 fillchar(f,sizeof(f),false);
12 fillchar(lk,sizeof(lk),0);
13 readln(m,n);
14 for i:=1 to m 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;
23 end;
24 end; { init }
25 function find(now :longint ):boolean;
26 var
27 i : longint;
28 begin
29 for i:=1 to n 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 m 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 readln(p);
55 for k:=1 to p do
56 begin
57 init;
58 if (main=m) then
59 writeln('YES')
60 else
61 writeln('NO');
62 end;
63 end.