Pagini recente » Cod sursa (job #1710002) | Cod sursa (job #1764700) | Cod sursa (job #2632009) | Cod sursa (job #260009) | Cod sursa (job #2484023)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
const int DIM = 50007;
vector <int> SET, REZ, L[DIM];
bool viz[DIM];
void topsort(int x)
{
SET.push_back(x);
viz[x] = true;
for(int i = 0 ; i < L[x].size() ; i++)
if(viz[L[x][i]] == false)
topsort(L[x][i]);
REZ.push_back(x);
}
int main()
{
int n,m;
in >> n >> m;
for(int i = 1; i <= m; i++)
{
int x, y;
in >> x >> y;
L[x].push_back(y);
}
for(int j = 1; j <= n; j++)
if(viz[j] == false)
topsort(j);
for( int i = REZ.size() - 1 ;i >= 0; i--)
out << REZ[i] <<" ";
return 0;
}