Pagini recente » Cod sursa (job #2315794) | Cod sursa (job #2207473) | Cod sursa (job #2785593) | Cod sursa (job #525747) | Cod sursa (job #1211827)
program sortaretopologica;
type lista=^celula;
celula=record
info:longint;
next:lista;
end;
var n,m,i,x,y,k:longint;
a:array[1..50000] of lista;
r:lista;
vis:array[1..50000] of byte;
sort:array[1..50000] of longint;
bufin,bufout:array[1..100000] of byte;
procedure dfs(x:longint);
var q:lista;
begin
vis[x]:=1;
q:=a[x];
while q<>nil do
begin
if vis[q^.info]=0 then dfs(q^.info);
q:=q^.next;
end;
sort[k]:=x;
dec(k);
end;
begin
assign(input,'sortaret.in');
reset(input);
settextbuf(input,bufin);
assign(output,'sortaret.out');
rewrite(output);
settextbuf(output,bufout);
readln(n,m);
for i:=1 to m do
begin
readln(x,y);
new(r);
r^.info:=y;
r^.next:=a[x];
a[x]:=r;
end;
k:=n;
for i:=1 to n do
begin
if vis[i]=0 then dfs(i);
end;
for i:=1 to n do write(sort[i],' ');
close(output);
end.