Pagini recente » Cod sursa (job #185812) | Cod sursa (job #2013719) | Istoria paginii runda/usu9/clasament | Cod sursa (job #1342631) | Cod sursa (job #1575664)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int nmax = 50005;
vector <int> g[nmax], sol;
bool viz[nmax];
void dfs(int dad)
{
int i, son;
viz[dad]=true;
for(i=0; i<g[dad].size(); i++)
{
son=g[dad][i];
if(!viz[son]) dfs(son);
}
sol.push_back(dad);
}
int main()
{
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
ios_base::sync_with_stdio(false);
int n, m, i, x, y;
fin >> n >> m;
for(i=1; i<=m; i++)
{
fin >> x >> y;
g[x].push_back(y);
}
for(i=1; i<=n; i++)
if(viz[i]==false) dfs(i);
for(i=sol.size()-1; i>=0; i--)
fout << sol[i] << " ";
fin.close();
fout.close();
return 0;
}