-
Notifications
You must be signed in to change notification settings - Fork 6
/
find_even_cycle.test.cpp
78 lines (72 loc) · 1.59 KB
/
find_even_cycle.test.cpp
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
#define PROBLEM "https://judge.yosupo.jp/problem/aplusb"
#include "my_template.hpp"
#include "random/random_graph.hpp"
#include "graph/find_even_cycle.hpp"
vc<int> find_even_cycle_naive(Graph<int, 0> G) {
int N = G.N;
vc<int> used_v(N);
vc<int> path;
vc<int> ANS;
auto dfs = [&](auto& dfs, int v, int p) -> void {
if (!ANS.empty()) return;
for (auto& e: G[v]) {
if (e.id == p) continue;
if (e.to == path[0] && len(path) % 2 == 0) {
ANS = path;
return;
}
if (!used_v[e.to]) {
used_v[e.to] = 1;
path.eb(e.to);
dfs(dfs, e.to, e.id);
POP(path);
used_v[e.to] = 0;
}
}
};
FOR(v, N) {
used_v[v] = 1;
path.eb(v);
dfs(dfs, v, -1);
used_v[v] = 0;
path.pop_back();
}
return ANS;
}
void test() {
FOR(N, 1, 15) {
FOR(1000) {
Graph<int, 0> G(N);
for (auto& [a, b]: random_graph<0>(N, false)) G.add(a, b);
G.build();
auto [vs, es] = find_even_cycle(G);
vc<int> ans = find_even_cycle_naive(G);
if (vs.empty()) {
assert(ans.empty());
continue;
}
assert(!ans.empty());
int n = len(es);
assert(n % 2 == 0);
assert(len(vs) == 1 + n);
assert(vs[0] == vs[n]);
FOR(i, n) {
int a = vs[i], b = vs[i + 1];
auto& e = G.edges[es[i]];
assert((e.frm == a && e.to == b) || (e.frm == b && e.to == a));
}
UNIQUE(vs);
assert(len(vs) == n);
}
}
}
void solve() {
int a, b;
cin >> a >> b;
cout << a + b << "\n";
}
signed main() {
test();
solve();
return 0;
}