Pagini recente » Cod sursa (job #692547) | Cod sursa (job #2564526) | Cod sursa (job #104222) | Cod sursa (job #419251) | Cod sursa (job #379204)
Cod sursa(job #379204)
type ref=^nod;
nod=record
vf:longint;
leg:ref;
end;
var prim:array[1..50000] of ref;
sel:array[1..50000] of 0..1;
sol:array[1..50000] of longint;
n,m,nr:integer;
procedure adaug(x,y:longint);
var c:ref;
begin
new(c);
c^.vf:=y;
c^.leg:=prim[x];
prim[x]:=c;
end;
procedure citire;
var x,y,i:longint;
begin
assign(input,'sortaret.in'); reset(input);
readln(n,m);
for i:=1 to m do
begin
readln(x,y);
adaug(x,y);
end;
close(input);
end;
procedure DF(i:integer);
var c:ref;
begin
sel[i]:=1;
c:=prim[i];
while c<>nil do
begin
if sel[c^.vf]=0 then DF(c^.vf);
c:=c^.leg;
end;
inc(nr);
sol[nr]:=i;
end;
procedure topolog;
var i:longint;
begin
assign(output,'sortaret.out'); rewrite(output);
for i:=1 to n do
if sel[i]=0 then df(i);
for i:=nr downto 1 do write(sol[i],' ');
close(output);
end;
begin
citire;
topolog;
end.