-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgraph.cpp
More file actions
85 lines (74 loc) · 1.69 KB
/
graph.cpp
File metadata and controls
85 lines (74 loc) · 1.69 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
/*
In the name of ALLAH
Author : Raashid Anwar
*/
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int M1 = 998244353;
const int M2 = 1000000007;
mt19937 rng((uint64_t)chrono::steady_clock::now().time_since_epoch().count());
class graph {
vector <vector <int>> node;
vector <pair<int, int>> bridges;
vector <int> in, out, low, vis;
int n, time_stamp;
public :
graph(int _n) : n(_n) {
node.resize(n);
in.resize(n);
out.resize(n);
low.resize(n);
vis.resize(n);
time_stamp = 0;
}
void add(int u, int v) {
node[u].push_back(v);
node[v].push_back(u);
}
void find_bridges(int u, int p) {
in[u] = low[u] = ++time_stamp;
vis[u] = 1;
for (int v : node[u]) {
if (!vis[v]) {
find_bridges(v, u);
low[u] = min(low[u], low[v]);
if (low[v] > in[u])
bridges.push_back({u, v});
}
if (p != v)
low[u] = min(low[u], in[v]);
}
out[u] = ++time_stamp;
}
bool check_cycle(int u, int p) {
if (vis[u])
return true;
vis[u] = true;
for (int v : node[u])
if (v != p)
if (check_cycle(v, u))
return true;
return false;
}
bool is_cycle() {
fill(vis.begin(), vis.end(), 0);
for (int u = 0; u < n; u++) {
if (vis[u] == 0 && check_cycle(u, -1))
return true;
}
return false;
}
vector <pair<int, int>> get_bridges() {
bridges.clear();
find_bridges(0, -1);
return bridges;
}
};
void solve() {
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
}