Pagini recente » Cod sursa (job #2298652) | Cod sursa (job #3295094) | Cod sursa (job #15318) | Cod sursa (job #2134977) | Cod sursa (job #2132874)
#include <bits/stdc++.h>
using namespace std;
const int mxn = 50 * 1000 + 10;
vector< int > v[ mxn ];
stack< int > s;
int n, m;
bool viz[ mxn ];
void dfs(int nod){
viz[ nod ] = 1;
for(auto it: v[ nod ])
if(viz[ it ] == 0)
dfs( it );
s.push( nod );
}
int main()
{
ios_base::sync_with_stdio( false );
cin.tie( 0 );
ifstream cin("sortaret.in");
ofstream cout("sortaret.out");
cin>> n >> m;
for(int i = 0, x, y; i < m; i++){
cin>> x >> y;
v[ x ].push_back( y );
}
for(int i = 1; i <= n; i++)
if(viz[ i ] == 0)
dfs( i );
while(!s.empty()){
cout<< s.top() << ' ';
s.pop();
}
return 0;
}