Pagini recente » Istoria paginii utilizator/robertpoe | Diferente pentru utilizator/dornescuvlad intre reviziile 12 si 102 | Istoria paginii utilizator/johnny07 | Diferente pentru utilizator/stay_awake77 intre reviziile 30 si 51 | Cod sursa (job #1909086)
#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 <= n; 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;
}