Pagini recente » Cod sursa (job #2794877) | Cod sursa (job #2337009) | Cod sursa (job #2875253) | Cod sursa (job #2254678) | Cod sursa (job #2174083)
#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(int i = 0; i < v[ nod ].size(); ++i)
if(viz[ v[ nod ][ i ] ] == 0)
dfs( v[ nod ][ i ] );
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;
}