Pagini recente » Cod sursa (job #161301) | Cod sursa (job #2765935) | Cod sursa (job #1798688) | Cod sursa (job #1698291) | Cod sursa (job #2786845)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
const int N=5e4+1;
int nrp[N];
vector<int> a[N];
queue<int> q;
int main()
{
int n,m;
in>>n>>m;
for(int i=1; i<=m; i++)
{
int x,y;
in>>x>>y;
nrp[y]++;
a[x].push_back(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: a[x])
{
nrp[y]--;
if(nrp[y]==0)
{
q.push(y);
}
}
}
return 0;
}