File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ // O(V + E)
2
+ // Euler path is a path that uses every edge in graph exactly once
3
+ // const int N = 1e5 + 50;
4
+ int n, in[N], out[N]; // in and out degrees
5
+ vector<int > path; // has the euler path in reverse order
6
+ queue<int > adj[N];
7
+
8
+ void dfs (int u)
9
+ {
10
+ while (adj[u].size ())
11
+ {
12
+ int v = adj[u].front ();
13
+ adj[u].pop ();
14
+ dfs (v);
15
+ }
16
+ path.push_back (u);
17
+ }
18
+
19
+ pair<bool , int > is_eulerian () // {is eulerian, start node of dfs}
20
+ {
21
+ int _s = 0 , _e = 0 , st = 1 ;
22
+ for (int u = 1 ; u < N; u++)
23
+ {
24
+ int sub = in[u] - out[u];
25
+ if (sub == -1 )
26
+ ++_s, st = u;
27
+ else if (sub == 1 )
28
+ ++_e;
29
+ else if (sub != 0 )
30
+ return {0 , -1 };
31
+ }
32
+ if (_s > 1 || _e > 1 || _s + _e == 1 )
33
+ return {0 , -1 };
34
+ return {1 , st};
35
+ }
You can’t perform that action at this time.
0 commit comments