Pagini recente » Cod sursa (job #2979603) | Cod sursa (job #2093930) | Cod sursa (job #1244509) | Cod sursa (job #2030041) | Cod sursa (job #2086712)
#include <bits/stdc++.h>
#define NMAX 50001
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n, m;
vector<int> V[NMAX];
bool use[NMAX];
struct nod{
int info;
nod *next;
}*L;
void addList(nod *&L, int x) {
if(L == NULL) {
L = new nod;
L->info = x;
L->next = NULL;
} else {
nod *p = new nod;
p->info = L->info;
p->next = L->next;
L->info = x;
L->next = p;
}
}
void printList(nod *&L) {
for(nod *p = L; p != NULL; p = p->next) {
fout << p->info << ' ';
}
}
void DFS(int nod) {
use[nod] = 1;
for(int i = 0; i < V[nod].size(); i++) {
if(!use[V[nod][i]])
DFS(V[nod][i]);
}
addList(L, nod);
}
int main()
{
fin >> n >> m;
int a, b;
while(m--) {
fin >> a >> b;
V[a].push_back(b);
}
DFS(1);
printList(L);
return 0;
}