Pagini recente » Cod sursa (job #1557879) | Cod sursa (job #1846170) | Cod sursa (job #2756499) | Cod sursa (job #1941730) | Cod sursa (job #1649702)
#include <iostream>
#include <fstream>
#include <vector>
#include <bitset>
using namespace std;
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
const int nmax = 5e4+5;
vector <int> g[nmax], sol;
bitset <nmax> viz;
void dfs(int dad)
{
vector <int> :: iterator son;
viz[dad]=true;
for(son=g[dad].begin(); son!=g[dad].end(); son++)
if(viz[*son]==false) dfs(*son);
sol.push_back(dad);
}
int main()
{
ios_base::sync_with_stdio(false);
int n, m, x, y, i;
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=n-1; i>=0; i--)
fout << sol[i] << " ";
fin.close();
fout.close();
return 0;
}