Pagini recente » Cod sursa (job #1839679) | Cod sursa (job #107300) | Cod sursa (job #1706945) | Istoria paginii utilizator/roxxaannee | Cod sursa (job #2716372)
#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e6 + 1;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n, m, nod;
vector <int> v[10005];
queue <int > q;
int check[nmax];
int verif[nmax];
int main()
{
fin >> n >> m;
for(int i = 1; i <= m; ++i)
{
int x, y;
fin >> x >> y;
v[x].push_back(y);
check[y] ++;
}
for(int i = 1; i <= n; ++i)
{
if(check[i] == 0)
q.push(i);
}
while(!q.empty())
{
nod = q.front();
fout << nod << " ";
q.pop();
for(int i = 0; i < v[nod].size(); ++i)
{
check[v[nod][i]] -- ;
if(check[v[nod][i]] == 0)
q.push(v[nod][i]);
}
}
return 0;
}