Pagini recente » Cod sursa (job #2616238) | Cod sursa (job #3262574) | Cod sursa (job #69848) | Cod sursa (job #1039546) | Cod sursa (job #156524)
Cod sursa(job #156524)
#include <stdio.h>
int n, m;
struct nod {
int x;
nod *urm;
};
nod *p[50000], *S;
void adaug(nod *&p, int y){
nod *q = new nod;
q -> x = y;
q -> urm = p;
p = q;
}
void citire(){
freopen("sortaret.in", "r", stdin);
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++){
int x, y;
scanf("%d %d", &x, &y);
adaug(p[x],y);
}
fclose(stdin);
}
void df(int x) {
for (nod *q = p[x]; q; q = q -> urm) {
df(q -> x);
adaug(S, q -> x);
}
}
void top() {
freopen("sortaret.out", "w", stdout);
printf("%d ", 1);
for (nod *q = S; q; q = q -> urm)
printf("%d ", q -> x);
fclose(stdout);
}
int main() {
citire();
df(1);
top();
return 0;
}