Pagini recente » Cod sursa (job #1160779) | Cod sursa (job #2298532) | Cod sursa (job #180948) | Cod sursa (job #1288900) | Cod sursa (job #2720992)
#include <fstream>
#include <queue>
using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
const int N = 50001;
int n, m;
int nrp[N];
vector<int>v[N];
queue<int>q;
int main()
{
in>>n>>m;
for(int i=0; i<m; i++)
{
int x,y;
in>>x>>y;
v[x].push_back(y);
nrp[y]++;
}
for(int i=1; i<=n; i++)
{
if(nrp[i] == 0)
{
q.push(i);
}
}
while(!q.empty())
{
int x = q.front();
out<<x<<" ";
q.pop();
for(auto y:v[x])
{
nrp[y]--;
if(nrp[y] == 0)
{
q.push(y);
}
}
}
return 0;
}