-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path291.cpp
More file actions
72 lines (65 loc) · 1.46 KB
/
291.cpp
File metadata and controls
72 lines (65 loc) · 1.46 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**Make it fast using eulers path algorithm current rating 2348**/
#include<bits/stdc++.h>
using namespace std;
map<int,vector<int> > G;
map<pair<int,int>,bool>visited;
vector<int>num;
int c = 0;
void dfs(int x){
num.push_back(x);
if(c == 8){
for(auto i : num){
cout<<i;
}
cout<<endl;
}
if(c != 8){
for(auto i :G[x]){
if(visited[{x,i}] == false){
visited[{x,i}] = true;
visited[{i,x}] = true;
c++;
dfs(i);
visited[{x,i}] = false;
visited[{i,x}] = false;
num.pop_back();
c--;
}
}
}
}
int main(){
G[1].push_back(2);
visited[pair<int,int>(1,2)] = false;
G[1].push_back(3);
visited[pair<int,int>(1,3)] = false;
G[1].push_back(5);
visited[pair<int,int>(1,5)] = false;
G[2].push_back(1);
visited[pair<int,int>(2,1)] = false;
G[2].push_back(3);
visited[pair<int,int>(2,3)] = false;
G[2].push_back(5);
visited[pair<int,int>(2,5)] = false;
G[3].push_back(1);
visited[pair<int,int>(3,1)] = false;
G[3].push_back(2);
visited[pair<int,int>(3,2)] = false;
G[3].push_back(4);
visited[pair<int,int>(3,4)] = false;
G[3].push_back(5);
visited[pair<int,int>(3,5)] = false;
G[4].push_back(3);
visited[pair<int,int>(4,3)] = false;
G[4].push_back(5);
visited[pair<int,int>(4,5)] = false;
G[5].push_back(1);
visited[pair<int,int>(5,1)] = false;
G[5].push_back(2);
visited[pair<int,int>(5,2)] = false;
G[5].push_back(3);
visited[pair<int,int>(5,3)] = false;
G[5].push_back(4);
visited[pair<int,int>(5,4)] = false;
dfs(1);
}