Pagini recente » Cod sursa (job #1356026) | Cod sursa (job #459558)
Cod sursa(job #459558)
#include <vector>
#include <cstdlib>
#include <fstream>
#include <iterator>
#define Nmax 50111
/*
*
*/
using namespace std;
bool wash[Nmax];
vector< int > dfs;
vector< int > G[Nmax];
inline void DFS( int x )
{
wash[x]=true;
if( G[x].empty() )
{
dfs.push_back(x);
return;
}
vector< int >::const_iterator it=G[x].begin(), iend=G[x].end();
for( ; it < iend; ++it )
if( false == wash[*it] )
DFS(*it);
dfs.push_back(x);
}
int main( void )
{
int N, M, x, y;
ifstream in( "sortaret.in" );
for( in>>N>>M; M; --M )
{
in>>x>>y;
G[x].push_back(y);
}
for( x=1; x <= N; ++x )
if( false == wash[x] )
DFS(x);
ofstream out( "sortaret.out" );
copy( dfs.rbegin(), dfs.rend(), ostream_iterator<int>( out, " " ) );
out<<'\n';
return EXIT_SUCCESS;
}