Pagini recente » Cod sursa (job #2098967) | Cod sursa (job #1731951) | Cod sursa (job #1288994) | Cod sursa (job #1111084) | Cod sursa (job #3219966)
#include <iostream>
#define FIN "sortaret.in"
#define FOUT "sortaret.out"
#define MAX 500005
struct Node {
int info;
struct Node *next;
};
int nodes,
edges,
visited[MAX];
struct Node *G[MAX],
*head = NULL;
void DFS( int node ) {
struct Node *c, *p;
visited[ node ] = 1;
for(c = G[ node ]; c; c = c->next) {
if(!visited[ c->info ]) {
DFS( c->info );
}
}
p = (struct Node*)malloc(sizeof(struct Node));
p->info = node;
p->next = head;
head = p;
}
int main(int argc, char const *argv[]) {
int i,j;
struct Node *c;
freopen(FIN, "r", stdin);
scanf("%d %d", &nodes, &edges);
while(edges--) {
scanf("%d %d", &i, &j);
c = (struct Node*)malloc(sizeof(struct Node));
c->info = j;
c->next = G[i];
G[i] = c;
}
for(int node = 1; i <= nodes; ++i) {
if(!visited[ node ]) {
DFS( node );
}
}
freopen(FOUT, "w", stdout);
for(c = head; c; c = c->next) {
printf("%d ", c->info);
}
return 0;
}