Pagini recente » Cod sursa (job #561878) | Cod sursa (job #284286) | Cod sursa (job #3166956) | Cod sursa (job #1908262) | Cod sursa (job #2781462)
#include <bits/stdc++.h>
#define NMAX 50005
#define pb push_back
using namespace std;
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
vector < int > v[NMAX];
queue < int > a;
int t[NMAX];
int main()
{
vector < int > :: iterator it;
int n, m, x, y, i;
fin >> n >> m;
while(m--)
{
fin >> x >> y;
v[x].pb(y);
t[y]++;
}
for(i = 1; i <= n; i++) if(t[i] == 0) a.push(i);
while(a.empty() == 0)
{
x = a.front();
a.pop();
fout << x << ' ';
for(it = v[x].begin(); it != v[x].end(); it++)
{
t[*it]--;
if(t[*it] == 0) a.push(*it);
}
}
return 0;
}