Pagini recente » Rating Stormie (Stormie) | Cod sursa (job #596307) | Cod sursa (job #2794727) | Cod sursa (job #2214818) | Cod sursa (job #2581175)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("sortaret.in");
ofstream f2("sortaret.out");
struct Nod{
int info;
Nod * next;
};
int viz[100005], n, m, x, y, i;
Nod listadeAdiacenta[100005];
int control[100005];
void adaugare(Nod * prim, int z){
Nod * newNode = new Nod;
newNode -> info = z;
newNode -> next = NULL;
Nod * it = prim;
while(it -> next != NULL){
it = it-> next;
}
it -> next = newNode;
}
int t = 1;
void dfs(int plecare){
if(viz[plecare] == 1){
return;
}
viz[plecare] = 0;
Nod * it = listadeAdiacenta[plecare].next;
while(it != NULL){
dfs(it -> info);
it = it -> next;
}
control[t] = plecare;
t++;
viz[plecare] = 1;
}
int main()
{
f >> n >> m;
for(i = 1; i <= n; i++){
viz[i] = 0;
}
for(i = 1; i <= m; i++){
f >> x >> y;
Nod * listaX = &listadeAdiacenta[x];
adaugare(listaX, y);
}
for(i = 1; i <= n; i++){
if(viz[i] == 0){
dfs(i);
}
}
for(i = n; i >= 1; i--){
f2 << control[i] << " ";
}
return 0;
}