Pagini recente » Cod sursa (job #2841646) | Arhiva de probleme | Cod sursa (job #1791728) | Cod sursa (job #2017860) | Cod sursa (job #2816897)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
vector <vector<int>>v;
int b[50001];int n,m;
void f()
{
queue <int> Q;
for (int l=1;l<=n;l++) if (b[l]==0) Q.push(l);
while (!Q.empty())
{
int i=Q.front();
Q.pop();
fout << i <<" ";
for (int j=0;j<v[i].size();j++)
{
b[v[i][j]]--;
if (b[v[i][j]]==0)
{
Q.push(v[i][j]);
}
}
}
}
int main()
{
fin >>n>>m;
v.resize(50001);
for (int i=1; i<=m; i++)
{
int x,y;
fin >>x>>y;
v[x].push_back(y);
b[y]++;
}
f();
}