Pagini recente » Cod sursa (job #1006473) | Cod sursa (job #1309051) | Cod sursa (job #2450424) | Cod sursa (job #1660896) | Cod sursa (job #2323504)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream in ("sortaret.in" );
ofstream out ("sortaret.out");
const int N = 50001, M = 100001;
vector < int > a[N];
queue <int> q;
int pred[N], sc[N];
int main()
{
int n, m;
in >> n >> m;
for ( int i = 0; i < m; i++ )
{
int x, y;
in >> x >> y;
a[x].push_back(y);
pred[y]++;
}
for ( int i = 1; i <= n; i++ )
{
if ( pred[i] == 0 )
{
q.push(i);
}
}
int cati = 1;
while ( !q.empty() )
{
int x = q.front();
out << x << " ";
q.pop();
for ( auto i : a[x] )
{
pred[i]--;
if ( pred[i] == 0 )
{
q.push(i);
}
}
}
return 0;
}