求问题所在?

应该对啊
program p1790;
var v1,v2,d,f,st:array[0..100010] of longint;
a:array[0..200010,1..2] of longint;
n,m:longint;
//
procedure init;
var i:longint;
begin
readln(n,m);
for i:=1 to m do
begin
readln(a[i,2],a[i,1]);inc(d[a[i,2]]);
end;
end;
//
function b(a1,a2:longint):boolean;
begin
if st[a1]<st[a2] then exit(true)
else exit(false);
end;
//
procedure swapp(a1,a2:longint);
var k:longint;
begin
k:=st[a1];st[a1]:=st[a2];st[a2]:=k;
end;
//
function pop:longint;
var i,p1,p2:longint;
begin
pop:=st[1];swapp(1,st[0]);dec(st[0]);
while ((p2<=st[0]) and b(p1,p2)) or ((p2+1<=st[0]) and b(p1,p2+1)) do
begin
if (p2+1<=st[0]) and b(p2,p2+1) then inc(p2);
swapp(p1,p2);p2:=p2 shl 1;
end;
end;
//
procedure push(p:longint);
var p1:longint;
begin
inc(st[0]);st[st[0]]:=p;p1:=st[0];
while not(p1 shr 1=0) and b(p1 shr 1,p1) do
begin
swapp(p1,p1 shr 1);
p1:=p1 shr 1;
end;
end;
//
procedure swap(a1,a2:longint);
var k:longint;
begin
k:=a[a1,1];a[a1,1]:=a[a2,1];a[a2,1]:=k;
k:=a[a1,2];a[a1,2]:=a[a2,2];a[a2,2]:=k;
end;
//
function bi(a1,a2:longint):boolean;
begin
if a[a1,1]<a[a2,1] then exit(true);
if (a[a1,1]=a[a2,1]) and (a[a1,2]<a[a2,2]) then exit(true);
exit(false);
end;
//
procedure fixdui(l,r:longint);
var p1,p2:longint;
begin
p1:=l;p2:=p1 shl 1;
while ((p2<=r) and bi(p1,p2)) or ((p2+1<=r) and bi(p1,p2+1)) do
begin
if (p2+1<=r) and bi(p2,p2+1) then inc(p2);
swap(p1,p2);p1:=p2;p2:=p2 shl 1;
end;
end;
//
procedure dsort;
var i:longint;
begin
for i:=m shr 1 downto 1 do fixdui(i,m);
for i:=1 to m-1 do
begin
swap(1,m-i+1);
fixdui(1,m-i);
end;
end;
//
procedure main;
var i,h1,j:longint;
begin
dsort;
for i:=1 to m do
begin
if a[i-1,1]<>a[i,1] then
begin
j:=a[i,1];v1[j]:=i;
end;
if a[i,1]<>a[i+1,1] then v2[j]:=i;
end;
for i:=n downto 1 do if d[i]=0 then push(i);
for i:=1 to n-1 do
begin
h1:=pop;f[h1]:=i;
if v1[h1]<>0 then
for j:=v1[h1] to v2[h1] do
begin
dec(d[a[j,2]]);
if d[a[j,2]]=0 then push(a[j,2]);
end;
end;
f[pop]:=n;
end;
//
procedure print;
var i:longint;
begin
for i:=1 to n do write(n-f[i]+1,' ');
end;
//
begin
init;
main;
print;
end.

0 条评论

目前还没有评论...

信息

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