回帖:program toponum;
var a:array[0..1000,0..1000]of longint;
ind:array[1..1000]of longint;
c:array[1..1000]of boolean;
num,n,m,ans:longint;
procedure init;
var i,j,x,y:longint;
begin
readln(n,m);
for i:=1 to m do
begin
readln(x,y);
a[x,y]:=1;
inc(ind[y]);
end;
end;
procedure predo;
var i,j:longint;
begin
num:=n;
for i:=1 to n do
if ind=0 then
begin
a[0,i]:=1;
ind:=1;
end;
end;
procedure topo(v:integer);
var i,j:longint;
begin
if num=0 then begin inc(ans);exit;end;
for i:=1 to n do
if a[v,i]>0 then
dec(ind);
for i:=1 to n do
if (ind=0)and(not c) then
begin
c:=true;
dec(num);
topo(i);
c:=false;
inc(num);
end;
for i:=1 to n do
if a[v,i]>0 then
inc(ind);
end;
begin
init;
predo;
topo(0);
writeln(ans);
end.
输入数据:
9 8
1 2
1 5
2 3
3 4
3 7
7 6
8 9
4 6
输出数据:
432