Cod sursa(job #1211268)

Utilizator Alex1199Alex Bercea Alex1199 Data 22 iulie 2014 11:50:52
Problema Sortare topologica Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.77 kb
var m:array[1..500,1..500] of 0..1;
    a:array[1..5000] of longint;
    i, j, k, n, t, x, y: longint;
    t1:boolean;
 procedure st(i:longint);
 var j:longint;
  begin
   for j:=1 to n do
     if m[i,j]=1 then
      begin
        m[i,j]:=0;
        dec(a[j]);
       end;
  end;
begin
 assign(input,'sortaret.in');
  reset(input);
  readln(n,t);
  For i:=1 to t do
  begin
    readln(x,y);
    m[x,y]:=1;
    inc(a[y]);
  end;
 close(input);

 Assign(output,'sortaret.out');
  rewrite(output);
   while not t1 do
    begin
     For i:=1 to n do
     begin
      t1:=false;
       if a[i]=0 then
       begin
          t1:=true;
          write(i,' ');
          a[i]:=-1;
          st(i);
       end;
     end;
    end;

 close(output);
end.