Pagini recente » Cod sursa (job #3194485) | Cod sursa (job #3152376) | Cod sursa (job #1480869) | Cod sursa (job #3040819) | Cod sursa (job #2487672)
#include <bits/stdc++.h>
#define NMAX 50005
using namespace std;
ifstream f ("sortaret.in");
ofstream g ("sortaret.out");
unsigned short n , x , y;
int m;
vector < vector < unsigned short > > a(NMAX);
queue < unsigned short > q;
int vec[50005];
int main()
{
unsigned short i;
f >> n >> m;
for(i = 1 ; i <= m ; i++)
{
f >> x >> y;
a[x].push_back(y);
++vec[y];
}
for(i = 1 ; i <= n ; i++)
if(vec[i] == 0)
q.push(i);
unsigned nod = 0;
while(!q.empty())
{
nod = q.front();
q.pop();
g << nod << ' ';
for(i = 0 ; i < a[nod].size() ; i++)
{
if(--vec[a[nod][i]] == 0)
q.push(a[nod][i]);
}
}
return 0;
}