-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathberjwin sequence.cpp
More file actions
90 lines (77 loc) · 2.45 KB
/
berjwin sequence.cpp
File metadata and controls
90 lines (77 loc) · 2.45 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* Eulerian path is a pth which traverse all the edges exactly once
* Eulerain circuits is a node which you can start traversing the graph from it and visist all edges exactly once then go back to this node
* Eulerian path and Eulerain circuits required there to be all nonzero degree nodes belong only to one component
* requirement of existence of Eulerain circuits in undirected graph is that all nodes has even degree
* requirement of existence of Eulerain path in undirected graph is that all nodes has even degree or there is exactly two nodes with odd degree (start and end)
* requirement of existence of Eulerain circuits in directed graph is that every node has equal indegree and outdegree
* requirement of existence of Eulerain path in directed graph is that that every node has equal indegree and outdegree or there is at most
one vertics with out-in = 1 and at most one node with in-out
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n))
typedef bitset<10> MASK;
void fast() {
cin.tie(0);
cin.sync_with_stdio(0);
}
unordered_map<string, int> e;
const int MAX = 2e5 + 4;
int in[MAX], out[MAX], n,t;
vector<vector<int>> adj(MAX);
vector<int> ans;
void findOutIn() {
for (int i = 1; i <= t; ++i)
for (auto to : adj[i])in[to]++, out[i]++;
}
int idx[MAX];
void dfs(int node,int val){
while(out[node]){
dfs(adj[node][--out[node]],out[node]-1);
}
ans.push_back(val);
}
void Hierholzer() {
findOutIn();
string s;
for (int i = 0; i < n-1; ++i) {
s+='0';
}
dfs(e[s],-1);
}
int main() {
fast();
cin >> n;
if(n==1)return cout<<"01",0;
for (int i = 0; i < (1 << (n - 1)); ++i) {
bitset<15> x = i;
string s=x.to_string();
reverse(all(s));
s = s.substr(0, n - 1);
e[s] = ++t;
}
for (int i = 0; i < (1 << (n - 1)); ++i) {
bitset<15> x = i;
string s=x.to_string();
reverse(all(s));
s = s.substr(0, n - 1);
int u = e[s];
s.erase(s.begin());
string tmp = s + '0';
string tmp1 = s + '1';
adj[u].push_back(e[tmp]);
adj[u].push_back(e[tmp1]);
}
Hierholzer();
ans.pop_back();
for (int i = 0; i < n-1; ++i) {
ans.push_back(0);
}
reverse(all(ans));
for (auto i : ans)cout << i;
}