Pagini recente » Cod sursa (job #1411764) | Cod sursa (job #2399692) | Cod sursa (job #2086212) | Cod sursa (job #2747695) | Cod sursa (job #2641983)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
const int N = 50005;
int n, m;
vector<int> g[N], sortTop;
bool viz[N];
void dfs(int nod)
{
viz[nod] = true;
for(int y : g[nod])
if(!viz[y])
dfs(y);
sortTop.push_back(nod);
}
int main()
{
fin >> n >> m;
for(int i = 0; i < m; i++)
{
int x, y;
fin >> x >> y;
g[x].push_back(y);
}
for(int i = 1; i <= n; i++)
if(!viz[i])
dfs(i);
for(int i = sortTop.size() - 1; i >= 0; i--)
fout << sortTop[i] << ' ';
fout << '\n';
return 0;
}