Pagini recente » Cod sursa (job #2154018) | Cod sursa (job #109554) | Cod sursa (job #333724) | Cod sursa (job #853318) | Cod sursa (job #494768)
Cod sursa(job #494768)
#include <vector>
#include <fstream>
#include <cstdlib>
#include <iterator>
#include <algorithm>
#define MAX_N 50011
using namespace std;
/*
*
*/
bool was[MAX_N];
vector< int > dfs;
vector< int > G[MAX_N];
inline void DFS( int x )
{
was[x]=true;
vector< int >::const_iterator it=G[x].begin(), iend=G[x].end();
for( ; it < iend; ++it )
if( !was[*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);
G[y].push_back(x);
}
for( x=1; x <= N; ++x )
if( !was[x] )
DFS(x);
ofstream out( "sortaret.out" );
copy( dfs.rbegin(), dfs.rend(), ostream_iterator<int>(out," " ) );
out<<'\n';
return EXIT_SUCCESS;
}