Pagini recente » Cod sursa (job #2783566) | Cod sursa (job #148769) | Cod sursa (job #373570) | Cod sursa (job #2999503) | Cod sursa (job #1357070)
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
const int N = 50001;
int n, m;
int pred[N];
vector<int> a[N];
queue<int> q;
void sortaret()
{
for(int i = 1; i <= n; i++)
if(pred[i] == 0)
q.push(i);
while(!q.empty())
{
int x = q.front();
q.pop();
out << x << ' ';
for(size_t i = 0; i < a[x].size(); i++)
{
int y = a[x][i];
if(--pred[y] == 0)
q.push(y);
}
}
}
void citire()
{
in >> n >> m;
for(int i = 1; i <= m; i++)
{
int x, y;
in >> x >> y;
a[x].push_back(y);
pred[y]++;
}
}
int main()
{
citire();
sortaret();
out << '\n';
return 0;
}