Pagini recente » Cod sursa (job #633174) | Cod sursa (job #2976038) | Cod sursa (job #2866230) | Cod sursa (job #583135) | Cod sursa (job #1995820)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
const int nMax = 50005;
int n, m, k;
int ans[nMax];
bool viz[nMax];
vector <int> L[nMax];
inline void Read()
{
int i, x, y;
fin >> n >> m;
for(i = 1; i <= m; i++)
{
fin >> x >> y;
L[x].push_back(y);
}
}
inline void Dfs(int nod)
{
viz[nod] = true;
for(auto it : L[nod])
if(!viz[it])
Dfs(it);
ans[++k] = nod;
}
inline void Write()
{
int i;
for(i = 1; i <= n; i++)
if(!viz[i])
Dfs(i);
for(i = k; i >= 1; i--)
fout << ans[i] << " ";
}
int main()
{
Read();
Write();
return 0;
}