Pagini recente » Borderou de evaluare (job #3364842) | Cod sursa (job #3365307) | Cod sursa (job #3364633) | Cod sursa (job #3364635) | Cod sursa (job #3364628)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n,m;
int f[100005];
vector<vector<int>> v;
void sortop(int a)
{
queue<int> q;
vector<int> rez;
rez.push_back(a);
q.push(a);
while(!q.empty())
{
int x = q.front();
q.pop();
for(auto y:v[x])
{
f[y]--;
if(f[y]==0)
{
q.push(y);
rez.push_back(y);
}
}
}
for(int i=0;i<n;i++)
fout << rez[i] << " ";
return;
}
int main()
{
fin >> n >> m;
v.resize(n+5);
int x,y;
for(int i=1;i<=m;i++)
{
fin >> x >> y;
v[x].push_back(y);
f[y]++;
}
for(int i=1;i<=n;i++)
{
if(f[i]==0)
{
sortop(i);
break;
}
}
return 0;
}