Mai intai trebuie sa te autentifici.
Cod sursa(job #2365335)
| Utilizator | Data | 4 martie 2019 13:02:24 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.72 kb |
#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();
}
}
