Pagini recente » Cod sursa (job #806763) | Cod sursa (job #791425) | Cod sursa (job #298264) | Cod sursa (job #2404616) | Cod sursa (job #2725339)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
const int N = 50001;
int nrp[N];
queue <int> q;
vector <int> a[N], a_t[N];
void adauga(int x, int y)
{
a[x].push_back(y);
}
void adaugaT(int x, int y)
{
a_t[y].push_back(x);
}
int main()
{
int n, m, x, y;
in >> n >> m;
for(int i = 1; i <= m; i++)
{
in >> x >> y;
adauga(x, y);
nrp[y]++;
}
for(int i = 1; i <= n; i++)
{
if(nrp[i] == 0)
q.push(i);
}
while(!q.empty())
{
x = q.front();
q.pop();
out << x << " ";
for(auto i:a[x])
{
nrp[i]--;
if(nrp[i] == 0)
q.push(i);
}
}
return 0;
}