Pagini recente » Cod sursa (job #1744084) | Cod sursa (job #2970519) | Cod sursa (job #2680029) | Cod sursa (job #2262994) | Cod sursa (job #1575594)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
vector<int> ans;
struct node{
int inf;
node *nxt;
};
node *L[50100];
int c[50100];
void add(node *&w, int n) {
node *nou = new node;
nou->inf = n;
nou->nxt = w;
w = nou;
}
int main()
{
ifstream f("sortaret.in");
ofstream g("sortaret.out");
int n, m, x, y;
f >> n >> m;
for(int i = 1; i <= m; i ++) {
f >> x >> y;
c[y] ++;
add(L[x], y);
}
bool ok = true;
while(ok) {
ok = false; int ies;
for(int i = 1; i <= n; i ++) {
if(c[i] == 0) ies = i, ok = true;
}
if(!ok) break;
for(node *p = L[ies]; p; p = p->nxt) {
c[p->inf] --;
}
ans.push_back(ies);
c[ies] = -1;
}
for(int i = 0; i < ans.size(); i ++) g << ans[i] << " ";
g << "\n";
return 0;
}