逆拓扑排序为何WA?

####程序:
program tpsort;
var
q,cd,tp:array[0..10000] of integer;
f:array[1..10000] of boolean;
rear,front,n,m,i,j,x,y:integer;
a:array[1..10000,1..10000] of integer;
begin
readln(n,m);
fillchar(a,sizeof(a),0);fillchar(cd,sizeof(cd),0);
for i:=1 to m do begin readln(x,y);a[x,y]:=1;inc(cd[x]);end;
fillchar(q,sizeof(q),0);fillchar(tp,sizeof(tp),0);
fillchar(f,sizeof(f),true);
rear:=0;front:=0;x:=0;
for i:=n downto 1 do if f[i] and (cd[i]=0) then break;
rear:=(rear+1) mod n;q[rear]:=i;
f[i]:=false;
repeat
front:=(front+1) mod n;
x:=x+1;tp[x]:=q[front];
for i:=1 to n do
if (cd[i]>0) and (a[i,q[front]]=1) then begin dec(cd[i]);a[i,q[front]]:=0;end;
for i:=n downto 1 do
if f[i] and (cd[i]=0) then begin rear:=(rear+1) mod n;q[rear]:=i;f[i]:=false;break;end;
until x=n;
for i:=x downto 1 do write(tp[i],' ');writeln;
readln;
end.
这题题解上说要用逆拓扑排序+堆优化。我直接写了个逆拓扑,没有超时却几乎全部WA。**到底怎么回事???急求教!!!**

评测结果
编译成功

测试数据 #0: WrongAnswer, time = 140 ms, mem = 196580 KiB, score = 0
测试数据 #1: Accepted, time = 125 ms, mem = 196588 KiB, score = 10
测试数据 #2: WrongAnswer, time = 125 ms, mem = 196584 KiB, score = 0
测试数据 #3: WrongAnswer, time = 140 ms, mem = 196584 KiB, score = 0
测试数据 #4: WrongAnswer, time = 140 ms, mem = 196584 KiB, score = 0
测试数据 #5: WrongAnswer, time = 140 ms, mem = 196584 KiB, score = 0
测试数据 #6: WrongAnswer, time = 156 ms, mem = 196584 KiB, score = 0
测试数据 #7: WrongAnswer, time = 125 ms, mem = 196584 KiB, score = 0
测试数据 #8: RuntimeError, time = 140 ms, mem = 196584 KiB, score = 0
测试数据 #9: WrongAnswer, time = 125 ms, mem = 196584 KiB, score = 0
RuntimeError, time = 1356 ms, mem = 196588 KiB, score = 10

1 条评论

  • 1

信息

ID
1790
难度
5
分类
图结构 | 拓扑排序数据结构 点击显示
标签
(无)
递交数
981
已通过
303
通过率
31%
被复制
10
上传者