Pagini recente » Cod sursa (job #991503) | Cod sursa (job #561526) | Cod sursa (job #2269189) | Cod sursa (job #2493838) | Cod sursa (job #2458496)
#include <fstream>
using namespace std;
ifstream f("sortaret.in");
ofstream g("sortaret.out");
int N,M,rez[50000],i;
bool a[50001][50001],viz[50001];
void sorttop(int ns){
viz[ns]=1;
rez[i++]=ns;
for (int j=1;j<=N;j++)
if (a[ns][j] && !viz[j]){
sorttop(j);
}
while (viz[ns]==1 && ns<=N) ns++;
if (ns!=N+1) sorttop(ns);
}
int main()
{
f<<N<<M;
for (int j=1;j<=M;j++){
int x1,x2;
f>>x1>>x2;
a[x1][x2]=1;
}
sorttop(1);
for (int j=0;j<i;j++) g<<rez[j]<<" ";
return 0;
}