Pagini recente » Cod sursa (job #2555952) | Cod sursa (job #867577) | Cod sursa (job #1930165) | Cod sursa (job #1652894) | Cod sursa (job #2365335)
#include <iostream>
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
queue< int >q;
vector< int >v[ 50005 ];
int N, M, x, y, i, nr[ 50005 ];
int main()
{
fin >> N >> M;
for ( i = 1; i <= M; i++ )
{
fin >> x >> y;
v[ x ].push_back( y );
nr[ y ]++;
}
for ( i = 1; i <= N; i++ )
if ( nr[ i ] == 0 )
q.push( i );
while ( !q.empty() )
{
fout << q.front() << ' ';
for( auto it:v[ q.front() ] )
{
nr[ it ]--;
/// if ( nr[ it ] == 0 )
q.push( it );
}
q.pop();
}
}