From c0046bd972d2316637ff41ab2254a2e7ef29dc60 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Sun, 2 Oct 2016 17:13:15 +0530 Subject: [PATCH 01/10] Added practice problems Added 2 practice problems to the circle-circle intersection article. --- src/geometry/circle-circle-intersection.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/geometry/circle-circle-intersection.md b/src/geometry/circle-circle-intersection.md index 5669d10b5..b2bb5a20c 100644 --- a/src/geometry/circle-circle-intersection.md +++ b/src/geometry/circle-circle-intersection.md @@ -32,3 +32,5 @@ The only degenerate case we need to consider separately is when the centers of t ## Practice Problems [RadarFinder](https://community.topcoder.com/stat?c=problem_statement&pm=7766) +[Runaway to a shadow - Codeforces](http://codeforces.com/problemset/problem/681/E) +[ASC 1 Problem F "Get out!"](http://codeforces.com/gym/100199/problem/F) From aaa5f6f70a2cc7f982db5a0fbc1872ce92fbb76d Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Mon, 3 Oct 2016 00:07:44 +0530 Subject: [PATCH 02/10] Added new lines and bullets --- src/geometry/circle-circle-intersection.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/geometry/circle-circle-intersection.md b/src/geometry/circle-circle-intersection.md index b2bb5a20c..675b5db16 100644 --- a/src/geometry/circle-circle-intersection.md +++ b/src/geometry/circle-circle-intersection.md @@ -31,6 +31,8 @@ The only degenerate case we need to consider separately is when the centers of t ## Practice Problems -[RadarFinder](https://community.topcoder.com/stat?c=problem_statement&pm=7766) -[Runaway to a shadow - Codeforces](http://codeforces.com/problemset/problem/681/E) -[ASC 1 Problem F "Get out!"](http://codeforces.com/gym/100199/problem/F) +- [RadarFinder](https://community.topcoder.com/stat?c=problem_statement&pm=7766) + +- [Runaway to a shadow - Codeforces Round #357](http://codeforces.com/problemset/problem/681/E) + +- [ASC 1 Problem F "Get out!"](http://codeforces.com/gym/100199/problem/F) From 5b81be923d3f9394aa306a5315f1987db960317c Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 4 Oct 2016 00:31:10 +0530 Subject: [PATCH 03/10] Translated article about finding bridges. Translated article about graphs relating to finding bridges in a graph offline. Translation of http://e-maxx.ru/algo/bridge_searching --- src/graph/bridge_searching.md | 85 +++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/graph/bridge_searching.md diff --git a/src/graph/bridge_searching.md b/src/graph/bridge_searching.md new file mode 100644 index 000000000..53da598fa --- /dev/null +++ b/src/graph/bridge_searching.md @@ -0,0 +1,85 @@ + + +# Searching for bridges + +Suppose that we are given an undirected graph. A bridge is defined as an edge, whose removal makes the graph disconnected(or more precisely, increases the number of connected components). You want to find all the bridges in a given graph. + +Informally, the problem is formulated as follows: Given a map of cities with roads between them, find all "important" roads, i.e. roads whose removal leads to disappearance of the path between some pair of cities. + +Below, we describe the algorithm based of [depth first search](http://e-maxx.ru/algo/dfs), having running time $O(n+m)$, where $n$ is the number of vertices, and $m$ is the number of edges in the graph. + +Note that the website also describes an [online algorithm for finding bridges](http://e-maxx.ru/algo/bridge_searching_online) - in contrast to the offline algorithm described here, the online algorithm is able to maintain all bridges in a graph that is changing(new edges are being added). + +## Algorithm + +Run [DFS](http://e-maxx.ru/algo/dfs) from an arbitrary vertex of the graph; lets denote it through $root$. We note the following fact(which is easy to prove): + +- Let's say we are in the DFS, and looking through the edges from vertex $v$. Then for some edge $(v, to)$, it is a bridge if the vertices $to$ and it's descendants in the DFS tree have no back-edges to vertex $v$ or any of it's ancestors. Otherwise, the edge must not be a bridge. (In fact, we check the condition that there is no other way from $v$ to $to$ except for edge $(v, to)$ traversing the DFS tree.) + +Now we have to learn how to effectively verify this fact for each vertex. For doing this, we use "time of entry into node", computed by the depth first search algorithm. + +So, let $tin[v]$ denote the the depth first search time of node $v$. Now, we introduce the array $fup[v]$, which is the minimum of $tin[v]$, the DFS time of all nodes $p$ that are connected to node $v$ via back-edge $(v, p)$ and all the values of $fup[to]$ for each vertex to which is a direct child of $v$ in the DFS tree. + +
 fup[v] = \min \cases{
+tin[v], & \cr
+tin[p], & {[...]
+ +Now, there is a back edge from node $v$ or it's descendants if there is a son $to$ of node $v$ such that $fup[to] \leq tin[v]$.(If $fup[to] = tin[v]$, it means back edge comes directly to $v$, otherwise it comes to some ancestor). + +Thus, if the current edge $(v, to)$ in the DFS tree satisfies $fup[to] > tin[v]$, then it must be a bridge; otherwise it isn't one. + +##Implementation + +Regarding the implementation, here we need to distinguish 3 cases: when we are on an edge to a child in DFS tree, when we try to go on a back edge to some ancestor and when we are going in the reverse direction to our parent. Therefore, these are the cases accordingly: + +- $used[to] = false$ - DFS tree edges criteria; +- $used[to] = true$ && $to \neq parent$ - back edge to some ancestor criteria; +- $to = parent$ - Criteria for edge to be edge to parent in DFS tree. + +Thus, to implement, we need a depth first search function with all the information for a current node. + +
const int MAXN = ...;
+vector<int> g[MAXN];
+bool used[MAXN];
+int timer, tin[MAXN], fup[MAXN];
+ 
+void dfs (int v, int p = -1) {
+	used[v] = true;
+	tin[v] = fup[v] = timer++;
+	for (size_t i = 0; i < g[v].size(); ++i) {
+		int to = g[v][i];
+		if (to == p)  continue;
+		if (used[to])
+			fup[v] = min (fup[v], tin[to]);
+		else {
+			dfs (to, v);
+			fup[v] = min (fup[v], fup[to]);
+			if (fup[to] > tin[v])
+				IS_BRIDGE(v,to);
+		}
+	}
+}
+ 
+void find_bridges() {
+	timer = 0;
+	for (int i = 0; i < n; ++i)
+		used[i] = false;
+	for (int i = 0; i < n; ++i)
+		if (!used[i])
+			dfs (i);
+} 
+ +Here, the main function calls function $find_bridges$ which produces necessary initialization and starts depth first search in all components of a graph. + +Function $IS$_$BRIDGE(a, b)$ - is a function that will produce output to the fact that edge $(a, b)$ is a bridge. + +Constant $MAXN$ at beginning of code is initialised to maximum number of nodes in the graph. + +It should be noted that this does not work correctly if multiple edges are present in the graph, as it actually ignores their presence. Of course, multiple edges must not be a part of the answer, so checks must be made in the function $IS$_$BRIDGE$. Another way to work with multiple edges more accurately is to transfer the number of edges by which we entered the current node(we all need to store this additionally). + +## Tasks in online judges + +The task list in which we aim to find bridges: + +- [UVA #796 "Critical Links" [difficulty: low]](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737) +- [UVA #610 "Street Directions" [difficulty: medium]](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=551) From 1a532ebe6f6173ac952daf6c2babdff9e1e455a1 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 4 Oct 2016 00:36:40 +0530 Subject: [PATCH 04/10] Corrected grammar --- src/graph/bridge_searching.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph/bridge_searching.md b/src/graph/bridge_searching.md index 53da598fa..7e30a73e7 100644 --- a/src/graph/bridge_searching.md +++ b/src/graph/bridge_searching.md @@ -79,7 +79,7 @@ It should be noted that this does not work correctly if multiple edges are prese ## Tasks in online judges -The task list in which we aim to find bridges: +Some tasks in which we aim to find bridges: - [UVA #796 "Critical Links" [difficulty: low]](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737) - [UVA #610 "Street Directions" [difficulty: medium]](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=551) From ad14de633e6bfe81fbb1d6751811b13bb954a2b1 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 4 Oct 2016 00:43:46 +0530 Subject: [PATCH 05/10] Added problem Added a hard problem http://codeforces.com/problemset/problem/555/E --- src/graph/bridge_searching.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/graph/bridge_searching.md b/src/graph/bridge_searching.md index 7e30a73e7..502000e07 100644 --- a/src/graph/bridge_searching.md +++ b/src/graph/bridge_searching.md @@ -83,3 +83,4 @@ Some tasks in which we aim to find bridges: - [UVA #796 "Critical Links" [difficulty: low]](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737) - [UVA #610 "Street Directions" [difficulty: medium]](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=551) +- [Case of the Computer Network (Codeforces Round #310 Div. 1 E)[difficulty: hard]](http://codeforces.com/problemset/problem/555/E) From f740ebbd5349ea2d92ea97c287c3b6f93d821883 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 4 Oct 2016 00:44:01 +0530 Subject: [PATCH 06/10] Update bridge_searching.md --- src/graph/bridge_searching.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graph/bridge_searching.md b/src/graph/bridge_searching.md index 502000e07..6de7237b3 100644 --- a/src/graph/bridge_searching.md +++ b/src/graph/bridge_searching.md @@ -83,4 +83,4 @@ Some tasks in which we aim to find bridges: - [UVA #796 "Critical Links" [difficulty: low]](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737) - [UVA #610 "Street Directions" [difficulty: medium]](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=551) -- [Case of the Computer Network (Codeforces Round #310 Div. 1 E)[difficulty: hard]](http://codeforces.com/problemset/problem/555/E) +- [Case of the Computer Network (Codeforces Round #310 Div. 1 E) [difficulty: hard]](http://codeforces.com/problemset/problem/555/E) From 12645edc2471b3f00733ff5897f882f058c81fa6 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 4 Oct 2016 00:50:17 +0530 Subject: [PATCH 07/10] Improved formatting Corrected formatting of underscore and added C++ code show/hide toggle. --- src/graph/bridge_searching.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/graph/bridge_searching.md b/src/graph/bridge_searching.md index 6de7237b3..636e67770 100644 --- a/src/graph/bridge_searching.md +++ b/src/graph/bridge_searching.md @@ -38,6 +38,8 @@ Regarding the implementation, here we need to distinguish 3 cases: when we are o Thus, to implement, we need a depth first search function with all the information for a current node. +C++ implementation Show/Hide +
const int MAXN = ...;
 vector<int> g[MAXN];
 bool used[MAXN];
@@ -69,7 +71,9 @@ void find_bridges() {
 			dfs (i);
 } 
-Here, the main function calls function $find_bridges$ which produces necessary initialization and starts depth first search in all components of a graph. + + +Here, the main function calls function $find$_$bridges$ which produces necessary initialization and starts depth first search in all components of a graph. Function $IS$_$BRIDGE(a, b)$ - is a function that will produce output to the fact that edge $(a, b)$ is a bridge. From 43fa0a9e3474c22cbb0f2168b5b93a9b78cf7b21 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 4 Oct 2016 08:10:20 +0530 Subject: [PATCH 08/10] Added note Noted the translator(myself). --- src/graph/bridge_searching.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/graph/bridge_searching.md b/src/graph/bridge_searching.md index 636e67770..c13b7327e 100644 --- a/src/graph/bridge_searching.md +++ b/src/graph/bridge_searching.md @@ -88,3 +88,5 @@ Some tasks in which we aim to find bridges: - [UVA #796 "Critical Links" [difficulty: low]](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737) - [UVA #610 "Street Directions" [difficulty: medium]](http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=551) - [Case of the Computer Network (Codeforces Round #310 Div. 1 E) [difficulty: hard]](http://codeforces.com/problemset/problem/555/E) + +####Note: Translated by [NibNalin](http://codeforces.com/profile/NibNalin) From 1603e1a47535aa2d13e287c4822f7a33e726eab5 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 4 Oct 2016 12:02:11 +0530 Subject: [PATCH 09/10] Rename bridge_searching.md to bridge-searching.md --- src/graph/{bridge_searching.md => bridge-searching.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/graph/{bridge_searching.md => bridge-searching.md} (100%) diff --git a/src/graph/bridge_searching.md b/src/graph/bridge-searching.md similarity index 100% rename from src/graph/bridge_searching.md rename to src/graph/bridge-searching.md From b916432bed2396bf6f5d65166589d38787a071e3 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 4 Oct 2016 12:03:29 +0530 Subject: [PATCH 10/10] Added link to index page Added link of bridges article to main index page. --- src/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.md b/src/index.md index d901aa149..8c3d71ed1 100644 --- a/src/index.md +++ b/src/index.md @@ -38,7 +38,7 @@ especially popular in field of competitive programming.* ### Graphs - [Kirchhoff theorem](./graph/kirchhoff-theorem.html) - [Topological sorting](./graph/topological-sort.html) - +- [Searching for bridges in O(N+M)](./graph/bridge-searching.html) --- [Information for contributors](./contrib.html) and [Test-Your-Page form](./test.php) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy