Skip to content
Snippets Groups Projects
Commit e8e9f941 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Add lowpoint (articulations_bridges)

parent be5335d4
No related branches found
No related tags found
No related merge requests found
/**
* Articulations and Bridges
*
* Complexity (Time): O(n + m)
* Complexity (Space): O(n + m)
*/
vector<int> graph[MAX];
int cont[MAX], parent[MAX];
int low[MAX], L[MAX];
// Find all articulations and bridges in the graph
void dfs(int x) {
int child = 0;
cont[x] = 1;
for (auto i : graph[x]) {
if (!cont[i]) {
child++;
parent[i] = x;
low[i] = L[i] = L[x] + 1;
dfs(i);
low[x] = min(low[x], low[i]);
if ((parent[x] == -1 && child > 1) || (parent[x] != -1 && low[i] >= L[x]))
// CAUTION: may be executed more than once for the same vertex
// ==== x is an articulation point ====
if (low[i] > L[x])
// ==== (x,i) is a bridge ====
} else if (parent[x] != i) {
low[x] = min(low[x], L[i]);
}
}
}
/**
* Breadth First Search - BFS
*
* Complexity (Time): O(|V| + |E|)
* Complexity (Space): O(|V| + |E|)
* Complexity (Time): O(n + m)
* Complexity (Space): O(n + m)
*/
bool cont[MAX];
......
/**
* Depth First Search - DFS
*
* Complexity (Time): O(|V| + |E|)
* Complexity (Space): O(|V| + |E|)
* Complexity (Time): O(n + m)
* Complexity (Space): O(n + m)
*/
bool cont[MAX];
......
/**
* Dijkstra
*
* Complexity (Time): O(|E| + |V| log |V|)
* Complexity (Space): O(|E| + |V|)
* Complexity (Time): O(m + n log n)
* Complexity (Space): O(n + m)
*/
int dist[MAX];
......
......@@ -5,7 +5,6 @@
* preprocess -> O(n log n)
* query -> O(log n)
* Complexity (Space): O(n + m + n log n)
*
*
* OBS: * = return sum path to LCA
* ** = return max value on path to LCA
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment