[BZOJ1612][Usaco2008 Jan]Cow Contest奶牛的比赛

来源:互联网 发布:销售数据分析岗位职责 编辑:程序博客网 时间:2024/05/17 02:08

传送门

http://www.lydsy.com/JudgeOnline/problem.php?id=1612

题目大意

给定m次比赛的结果,询问能够确定名次的人数

题解

能够确定名次,即这个人前面的人数加后面的人数为n-1
所以,传递闭包,Floyd处理即可

var x,y:array[0..100,0..100]of longint; i,j,k:longint; n,m,ans,tt,a,b:longint;begin readln(n,m); for i:=1 to m do  begin   readln(a,b);   x[b,a]:=1;   y[a,b]:=1;  end; for k:=1 to n do  for i:=1 to n do   for j:=1 to n do    begin     if (x[i,k]=1)and(x[k,j]=1)     then x[i,j]:=1;     if (y[i,k]=1)and(y[k,j]=1)     then y[i,j]:=1;    end; ans:=0; for i:=1 to n do  begin   tt:=0;   for j:=1 to n do    if (i<>j)and((x[i,j]=1)or(y[i,j]=1))    then inc(tt);   if tt=n-1 then inc(ans);  end; writeln(ans);end.
0 0
原创粉丝点击