Pagini recente » Cod sursa (job #1815864) | Cod sursa (job #1796682) | Cod sursa (job #2057153) | Cod sursa (job #238217) | Cod sursa (job #571356)
Cod sursa(job #571356)
const
nmax=50000;
type
npointer=^pointer;
pointer=record
inf:longint;
urm:npointer;
end;
var
g:array[1..nmax] of npointer;
top:array[1..nmax] of longint;
n,x,y,timp:integer;
i,m:longint;
use:array[1..nmax] of boolean;
procedure adauga(i,j:longint);
var
p:npointer;
begin
new(p);
p^.inf:=j;
p^.urm:=g[i];
g[i]:=p;
end;
procedure df(nod:longint);
var
p:npointer;
begin
use[nod]:=true;
p:=g[nod];
while p<>nil do begin
if use[p^.inf]=false then
df(p^.inf);
p:=p^.urm;
end;
inc(timp);
top[timp]:=nod;
end;
begin
fillchar(use,sizeof(use),false);
fillchar(top,sizeof(top),0);
assign(input,'sortaret.in');reset(input);
timp:=0;
readln(n,m);
for i:=1 to m do begin
readln(x,y);
adauga(x,y);
end;
close(input);
for i:=1 to n do begin
if use[i]=false then df(i);
end;
assign(output,'sortaret.out');rewrite(output);
for i:=n downto 1 do write(top[i],' ');
close(output);
end.