Pagini recente » Cod sursa (job #976229) | Cod sursa (job #3142483) | Cod sursa (job #1191599) | Cod sursa (job #690292) | Cod sursa (job #2162151)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
const int nMax = 50005;
int N, M, top;
vector <int> L[nMax];
int viz[nMax], ans[nMax];
inline void Read()
{
int x, y;
fin >> N >> M;
for(int i = 1; i <= M; i++)
{
fin >> x >> y;
L[x].push_back(y);
}
}
inline void Dfs(int node)
{
viz[node] = 1;
for(auto it : L[node])
if(!viz[it])
Dfs(it);
ans[++top] = node;
}
int main()
{
Read();
for(int i = 1; i <= N; i++)
if(!viz[i])
Dfs(i);
for(int i = N; i >= 1; i--)
fout << ans[i] << " ";
return 0;
}