Pagini recente » Cod sursa (job #1359351) | Cod sursa (job #905050)
Cod sursa(job #905050)
# include <fstream>
# define dim 50001
# include <vector>
using namespace std;
vector< vector < int > > mat( dim );
vector< int > v, grad( dim ), uz( dim );
int n,m;
inline void df( int x )
{
v.push_back( x );
for(int i=0; i<mat[ x ].size(); ++i )
if( ! uz[ mat[ x ][ i ] ] )
uz[ mat[ x ][ i ] ] = 1, df( mat[ x ][ i ] );
}
inline void citire()
{
ifstream fin("sortaret.in");
fin >> n >> m;
for(; m; --m )
{
int x,y;
fin >> x >> y;
mat[ x ].push_back( y );
grad[ y ]++;
}
for(int i=1; i<=n; ++i )
if( grad[ i ] == 0 )
df( i );
}
inline void afisare()
{
ofstream fout("sortaret.out");
for(int i=0; i<v.size(); ++i )
fout << v[ i ] <<" ";
}
int main()
{
citire();
afisare();
}