forked from oeddyo/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht.cpp
More file actions
35 lines (29 loc) · 607 Bytes
/
t.cpp
File metadata and controls
35 lines (29 loc) · 607 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <list>
using namespace std;
int graph[100][100];
int n, x, y, steps;
list<int> path;
void walk(int pos){
for(int i = 0; i < n; i++){
if(graph[pos][i] > 0){
graph[pos][i] --;
graph[i][pos] --;
walk(i);
}
}
path.push_back(pos+1);
}
int main(){
cin >> n;
for(int i = 0; i < n; i++){
cin >> x >> y;
graph[x-1][y-1] ++; //we are using zero index
graph[y-1][x-1] ++;
}
walk(0);
while(!path.empty()){
cout << path.back() << ' ';
path.pop_back();
}
}