-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Asad
committed
Jun 29, 2023
1 parent
6c5f57c
commit 0840a23
Showing
3 changed files
with
132 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const int N = 2e5; | ||
int tin[N+5], low[N+5]; | ||
bool vis[N+5]; | ||
vector<int> edge[N+5]; | ||
vector<pair<int, int> > art_bridge; | ||
|
||
int timer = 0; | ||
void dfs(int u, int p = -1){ | ||
tin[u] = low[u] = timer++; | ||
vis[u] = 1; | ||
|
||
for(int to : edge[u]){ | ||
if(vis[to]){ | ||
low[u] = min(low[u], tin[to]); | ||
} | ||
else{ | ||
dfs(to, u); | ||
|
||
low[u] = min(low[u], low[to]); | ||
if(low[to] > tin[u]){ | ||
art_bridge.push_back({u, to}); | ||
} | ||
} | ||
} | ||
} | ||
void cut_bridge(int n) | ||
{ | ||
timer = 0; | ||
art_bridge.clear(); | ||
for(int K = 1; K <= n; K++) vis[K] = 0; | ||
|
||
for(int K = 1; K <= n; K++){ | ||
if(!vis[K]){ | ||
dfs(K); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const int N = 2e5; | ||
int tin[N+5], low[N+5]; | ||
bool vis[N+5]; | ||
vector<int> art_point, edge[N+5]; | ||
|
||
int timer = 0; | ||
void dfs(int u, int p = -1){ | ||
tin[u] = low[u] = timer++; | ||
vis[u] = 1; | ||
|
||
int child = 0; | ||
for(int to : edge[u]){ | ||
if(to == p) continue; | ||
|
||
if(vis[to]){ | ||
low[u] = min(low[u], tin[to]); | ||
} | ||
else{ | ||
dfs(to, u); | ||
|
||
low[u] = min(low[u], low[to]); | ||
if(low[to] >= tin[u] && p != -1){ | ||
art_point.push_back(u); | ||
} | ||
++child; | ||
} | ||
} | ||
if(p == -1 && child >= 2){ | ||
art_point.push_back(u); | ||
} | ||
} | ||
void cut_point(int n) | ||
{ | ||
timer = 0; | ||
art_point.clear(); | ||
for(int K = 1; K <= n; K++) vis[K] = 0; | ||
|
||
for(int K = 1; K <= n; K++){ | ||
if(!vis[K]){ | ||
dfs(K); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|