Pagini recente » Cod sursa (job #674529) | Cod sursa (job #2526145) | Cod sursa (job #1729916) | Cod sursa (job #2643831) | Cod sursa (job #446012)
Cod sursa(job #446012)
/*
* File: main.cpp
* Author: virtualdemon
*
* Created on April 24, 2010, 7:06 PM
*/
#include <vector>
#include <cstdlib>
#include <fstream>
#include <iterator>
#define Nmax 50001
/*
*
*/
using namespace std;
bool uz[Nmax];
vector< int > dfn;
vector< int > G[Nmax];
inline void DFS( int x )
{
uz[x]=true;
vector< int >::const_iterator it=G[x].begin(), iend=G[x].end();
for( ; it < iend; ++it )
if( !uz[*it] )
DFS( *it );
dfn.push_back( x );
}
int main(int argc, char** argv)
{
int N, M, x, y;
ifstream in( "sortaret.in" );
in>>N>>M;
for( ; M; --M )
{
in>>x>>y;
G[x].push_back(y);
}
for( x=1; x <= N; ++x )
if( !uz[x] )
DFS(x);
ofstream out( "sortaret.out" );
copy( dfn.rbegin(), dfn.rend(), ostream_iterator<int>( out, " " ) );
out<<'\n';
return (EXIT_SUCCESS);
}