Pagini recente » Cod sursa (job #1626796) | Cod sursa (job #2904293) | Cod sursa (job #1839320) | Cod sursa (job #2563049) | Cod sursa (job #2716375)
#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[100005];
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;
}