Pagini recente » Cod sursa (job #1020016) | Cod sursa (job #195473) | Cod sursa (job #1242407) | Rating Jennifer (jennifer) | Cod sursa (job #2101245)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
const int Mmax = 100001;
const int Nmax = 50001;
int gr[Mmax] , n , m;
priority_queue < int > Q;
vector < int > L[Nmax];
int main()
{
fin >> n >> m;
for(int i = 1 ; i <= m ; i++)
{
int x , y;
fin >> x >> y;
L[x] . push_back(y);
gr[y]++;
}
for(int i = 1 ; i <= n ; i++)
if(gr[i] == 0)
Q.push(- i);
while(! Q . empty())
{
int x = - Q . top();
fout << x << " ";
Q . pop();
for(auto i : L[x])
{
gr[i]--;
if(gr[i] == 0)
Q.push( - i);
}
}
fout << "\n";
fin.close();
fout.close();
return 0;
}