Pagini recente » Cod sursa (job #1799770) | Cod sursa (job #958558) | Cod sursa (job #1686633) | Cod sursa (job #2309170) | Cod sursa (job #2000630)
#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;
}