Pagini recente » Cod sursa (job #455412) | Cod sursa (job #82989) | Cod sursa (job #1640314) | Cod sursa (job #2705946) | Cod sursa (job #596087)
Cod sursa(job #596087)
const f = 'sortaret.in'; g = 'sortaret.out';
type pnod = ^nod;
nod = record
next : pnod;
info : longint;
end;
var
a : array[0..100001] of pnod;
viz : array[0..100001] of byte;
st: array[0..100001] of longint;
x, y, start, m, n : longint;
i, ct : longint;
varf : pnod;
buf, buf1 : array[1..1 shl 17] of char;
procedure add( var dest : pnod; val : longint );
var
q : pnod;
begin
new( q );
q^.info := val;
q^.next := dest;
dest := q;
end;
procedure dfs( nod : longint );
var
q : pnod;
begin
viz[nod] := 1;
q := a[nod];
while q <> nil do begin
if viz[q^.info] = 0 then dfs( q^.info );
q := q^.next;
end;
inc( ct );
st[ct] := nod;
end;
begin
assign( input,f ); reset( input );
assign( output,g ); rewrite( output );
settextbuf( input,buf );
settextbuf( output,buf1 );
readln(n, m );
for i:=1 to m do begin
readln(x, y);
add( a[x], y );
end;
ct := 0;
for i := 1 to n do
if viz[i] = 0 then begin
dfs( i );
end;
for i := n downto 1 do write(st[i],' ');
end.