pku3360 Cow Contest
给一些牛的排名关系,问有多少牛的排名确定。
如果A比B强,就由A向B连边,之后求出这个图的传递闭包,对于一头牛,如果比它强的+比它弱的=N-1,它的排名一定。
View Code
1 program pku3660(input,output);
2 var
3 g : array[0..101,0..101] of boolean;
4 answer : longint;
5 n,m : longint;
6 procedure init;
7 var
8 i,x,y : longint;
9 begin
10 fillchar(g,sizeof(g),false);
11 readln(n,m);
12 for i:=1 to m do
13 begin
14 readln(x,y);
15 g[x,y]:=true;
16 end;
17 end; { init }
18 procedure floyd();
19 var
20 i,j,k : longint;
21 begin
22 for k:=1 to n do
23 for i:=1 to n do
24 if (i<>k) then
25 for j:=1 to n do
26 if (k<>j)and(i<>j) then
27 g[i,j]:=g[i,j] or(g[i,k] and g[k,j]);
28 end; { floyd }
29 procedure main;
30 var
31 i,j : longint;
32 sum : longint;
33 begin
34 answer:=0;
35 for i:=1 to n do
36 begin
37 sum:=0;
38 for j:=1 to n do
39 if (i<>j) then
40 if (g[i,j])or(g[j,i]) then
41 inc(sum);
42 if sum=n-1 then
43 inc(answer);
44 end;
45 end; { main }
46 procedure print;
47 begin
48 writeln(answer);
49 end; { print }
50 begin
51 init;
52 floyd;
53 main;
54 print;
55 end.