Pagini recente » Istoria paginii runda/asta_i_pt_shumen | Istoria paginii runda/plictiseala/clasament | Cod sursa (job #2079077) | Istoria paginii runda/cdib_6789/clasament | Cod sursa (job #2718744)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
const int N = 50001;
vector <int> a[N];
queue <int> q;
int n, m, nrp[N];
int main()
{
ifstream in("sortaret.in");
ofstream out("sortaret.out");
in >> n >> m;
for (int i = 0; i < m; i++)
{
int x, y;
in >> x >> y;
a[x].push_back(y);
nrp[y]++;
}
in.close();
for (int i = 1; i <= n; i++)
{
if (nrp[i] == 0)
{
q.push(i);
}
}
while (!q.empty())
{
int x = q.front();
q.pop();
out << x << " ";
for (auto y: a[x])
{
nrp[y]--;
if (nrp[y] == 0)
{
q.push(y);
}
}
}
out.close();
return 0;
}