题意:n个牛,给出m场比赛的比赛结果(前面的赢后面的),能力强的总是赢能力弱的,求最多有几头牛能确定能力排名
第一眼看题再看数据范围,第一反应不是网络流就是建有向边搞图...
当一个牛的能力可以确定时,当且仅当能赢它的牛加上输给它的牛有n-1头
可以发现,赢和输的信息是可以传递的
即当i能赢k且k能赢j时,i也能赢j。输的信息同理
这样我们就能找到所有能赢i的牛和输给i的牛
分别记录赢和输的信息,floyd跑传递闭包,最后对每一头牛判断赢它和输它的牛的总和是否等于n-1即可
var
n,m,tt,ans,x,y :longint;
win,lose :array[0..110,0..110] of boolean;
i,j,k :longint;
begin
read(n,m);
for i:=1 to m do
begin
read(x,y);
win[x,y]:=true;
lose[y,x]:=true;
end;
//
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if (i<>k) and (i<>j) and (j<>k) then
begin
if win[i,k] and win[k,j] then win[i,j]:=true;
if lose[i,k] and lose[k,j] then lose[i,j]:=true;
end;
//
ans:=0;
for i:=1 to n do
begin
tt:=0;
for j:=1 to n do
if win[i,j] or lose[i,j] then inc(tt);
if tt=n-1 then inc(ans);
end;
writeln(ans);
end.
——by EIrlys