Graph Algorithms.

Slides:



Advertisements
Similar presentations
Comp 122, Spring 2004 Graph Algorithms – 2. graphs Lin / Devi Comp 122, Fall 2004 Identification of Edges Edge type for edge (u, v) can be identified.
Advertisements

Comp 122, Fall 2004 Elementary Graph Algorithms. graphs Lin / Devi Comp 122, Fall 2004 Graphs  Graph G = (V, E) »V = set of vertices »E = set of.
Tirgul 7 Review of graphs Graph algorithms: –DFS –Properties of DFS –Topological sort.
Elementary Graph Algorithms Depth-first search.Topological Sort. Strongly connected components. Chapter 22 CLRS.
Lecture 16: DFS, DAG, and Strongly Connected Components Shang-Hua Teng.
CS 473Lecture 141 CS473-Algorithms I Lecture 14-A Graph Searching: Breadth-First Search.
More Graphs COL 106 Slides from Naveen. Some Terminology for Graph Search A vertex is white if it is undiscovered A vertex is gray if it has been discovered.
David Luebke 1 5/9/2015 CS 332: Algorithms Graph Algorithms.
Graph Searching (Graph Traversal) Algorithm Design and Analysis Week 8 Bibliography: [CLRS] – chap 22.2 –
CS 3343: Analysis of Algorithms Lecture 24: Graph searching, Topological sort.
1 Graph Programming Gordon College. 2 Graph Basics A graph G = (V, E) –V = set of vertices, E = set of edges –Dense graph: |E|  |V| 2 ; Sparse graph:
Graphs - Definition G(V,E) - graph with vertex set V and edge set E
Tirgul 8 Graph algorithms: Strongly connected components.
Tirgul 11 DFS Properties of DFS Topological sort.
Applications of graph traversals
CS 473Lecture 151 CS473-Algorithms I Lecture 15 Graph Searching: Depth-First Search and Topological Sort.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
CPSC 311, Fall CPSC 311 Analysis of Algorithms Graph Algorithms Prof. Jennifer Welch Fall 2009.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Makeup Lecture Chapter 23: Graph Algorithms Depth-First SearchBreadth-First.
CPSC 411 Design and Analysis of Algorithms Set 8: Graph Algorithms Prof. Jennifer Welch Spring 2011 CPSC 411, Spring 2011: Set 8 1.
1 Data Structures DFS, Topological Sort Dana Shapira.
Lecture 10 Topics Application of DFS Topological Sort
CSE 780 Algorithms Advanced Algorithms Graph Alg. DFS Topological sort.
Tirgul 11 BFS,DFS review Properties Use. Breadth-First-Search(BFS) The BFS algorithm executes a breadth search over the graph. The search starts at a.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
Tirgul 7 Review of graphs Graph algorithms: – BFS (next tirgul) – DFS – Properties of DFS – Topological sort.
November 6, Algorithms and Data Structures Lecture XI Simonas Šaltenis Aalborg University
David Luebke 1 10/1/2015 CS 332: Algorithms Topological Sort Minimum Spanning Tree.
COSC 3101A - Design and Analysis of Algorithms 10
Elementary Graph Algorithms CSc 4520/6520 Fall 2013 Slides adapted from David Luebke, University of Virginia and David Plaisted, University of North Carolina.
Spring 2015 Lecture 10: Elementary Graph Algorithms
Sept Elementary Graph Algorithms Graph representation Graph traversal -Breadth-first search -Depth-first search Parenthesis theorem.
Elementary Graph Algorithms CLRS Chapter 22. Graph A graph is a structure that consists of a set of vertices and a set of edges between pairs of vertices.
Graphs.
CSC 413/513: Intro to Algorithms Graph Algorithms DFS.
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Jan Topological Order and SCC Edge classification Topological order Recognition of strongly connected components.
1 Chapter 22 Elementary Graph Algorithms. 2 Introduction G=(V, E) –V = vertex set –E = edge set Graph representation –Adjacency list –Adjacency matrix.
Elementary Graph Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
 2004 SDU Lectrue4-Properties of DFS Properties of DFS Classification of edges Topological sort.
CSC 201: Design and Analysis of Algorithms Lecture # 18 Graph Algorithms Mudasser Naseer 1 12/16/2015.
1 Chapter 22: Elementary Graph Algorithms II. 2 About this lecture Depth First Search DFS Tree and DFS Forest Properties of DFS Parenthesis theorem (very.
Graph Algorithms Searching. Review: Graphs ● A graph G = (V, E) ■ V = set of vertices, E = set of edges ■ Dense graph: |E|  |V| 2 ; Sparse graph: |E|
Chapter 22: Elementary Graph Algorithms
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 20.
David Luebke 1 1/6/2016 CS 332: Algorithms Graph Algorithms.
CS 2133: Algorithms Intro to Graph Algorithms (Slides created by David Luebke)
David Luebke 1 1/25/2016 CSE 207: Algorithms Graph Algorithms.
Liaquat Majeed Sheikh 1 1/25/2016 Graph Algorithms.
Shahed University Dr. Shahriar Bijani May  A path is a sequence of vertices P = (v 0, v 1, …, v k ) such that, for 1 ≤ i ≤ k, edge (v i – 1, v.
 2004 SDU 1 Lecture5-Strongly Connected Components.
November 19, Algorithms and Data Structures Lecture XI Simonas Šaltenis Nykredit Center for Database Research Aalborg University
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
Chapter 22: Elementary Graph Algorithms Overview: Definition of a graph Representation of graphs adjacency list matrix Elementary search algorithms breadth-first.
Graph Algorithms – 2. graphs Parenthesis Theorem Theorem 22.7 For all u, v, exactly one of the following holds: 1. d[u] < f [u] < d[v] < f [v] or.
CS 3343: Analysis of Algorithms Lecture 24: Graph searching, Topological sort.
CS138A Elementary Graph Algorithms Peter Schröder.
Introduction to Algorithms
Chapter 22 Elementary Graph Algorithms
Main algorithm with recursion: We’ll have a function DFS that initializes, and then calls DFS-Visit, which is a recursive function and does the depth first.
CSC317 Graph algorithms Why bother?
CS 3343: Analysis of Algorithms
Graph Algorithms – 2 DAGs Topological order
Graph Representation Adjacency list representation of G = (V, E)
Lecture 10 Algorithm Analysis
Graph Algorithms – 2.
Advanced Algorithms Analysis and Design
Advanced Algorithms Analysis and Design
Basic Graph Algorithms
Graph Algorithms "A charlatan makes obscure what is clear; a thinker makes clear what is obscure. " - Hugh Kingsmill CLRS, Sections 22.2 – 22.4.
Presentation transcript:

Graph Algorithms

Representations of graphs:undirected graph An undirected graph G have five vertices and seven edges An adjacency-list representation of G The adjacency-matrix representation of G edge 1 2 3 4 5 vertex 1 2 5 / 2 1 5 3 4 / 3 2 4 / 4 2 5 3 / 5 4 1 1 / 1 2 3 4 5 1 1 1 2 1 1 1 1 3 1 1 4 1 1 1 5 1 1

Representations of graphs:directed graph An directed graph G have six vertices and eight edges An adjacency-list representation of G The adjacency-matrix representation of G 1 2 3 4 5 6 1 2 4 / 5 3 6 1 2 3 4 5 6 1 1 1 2 1 3 1 1 4 1 5 1 6 1

Time Complexity: O(|E|+|V|) BFS(G,s) for each vertex u∈ G.V-{s} u.color = WHITE u.d = ∞ u.π = NIL s.color = GREEN s.d = 0 s.π = NIL Q = empty Enqueue(Q,s) while Q ≠ empty u = Dequeue(Q) for each v∈ G.Adj[u] if v.color == WHITE v.color = GREEN v.d = u.d + 1 v.π = u Enqueue(Q,v) u.color = BLACK Time Complexity: O(|E|+|V|) 第一個迴圈,初始化除s外所有的節點成白色,距離無限大,前一個點為空。 之後初始化s為綠色,距離0,前一個點是空。至此花去O(|V|) 接下來將s放入Q中,之後反覆執行Dequeue,直到Q空了為止。 每個Dequeue出來的點u,均將其白色的鄰居放入Q中, 並且將他們塗成綠色,距離設定成d[u]+1以及將前一個點設定為u。 處理完所有的鄰居之後,就將u塗成紅色。 因此每個點被放入Q一次,並且一個點被檢驗是不是白色的總次數為|E|, 故此部分花費O(|E|+|V|)的時間。 Elementary Graph Algorithms

The operation of BFS on an undirected graph 1 1 v w x y v w x y Q Q s w r 1 1 (c) r s t u (d) r s t u 1 2 1 2 1 2 2 1 2 v w x y v w x y Q r t x Q t x v 1 2 2 1 2 2 (e) r s t u (f) r s t u 1 2 3 1 2 3 2 1 2 2 1 2 3 v w x y v w x y Q x v u Q v u y 2 2 3 2 3 3

(g) r s t u (h) r s t u 1 2 3 1 2 3 2 2 1 2 3 2 1 2 3 v w x y v w x y Q u y y 3 3 3 (i) r s t u 1 2 3 2 1 2 3 v w x y Q

Breadth-first search: Initially, vertices are colored white. Discovered vertices are colored green. When done, discovered vertices are colored black. u.d stores the distance from s to u. u.π is a predecessor to u on its shortest path. Q is a first-in first-out queue.

Properties of Breadth-first search: After execution of BFS, all nodes reachable from the source s are colored black. After execution of BFS, v.d is the distance of a shortest path from the source s to v for vertices v reachable from s. After execution of BFS, if v is reachable from s, then one of the shortest paths to v passes through the edge( v.π, v) at the end. After execution of BFS, the edges( v.π, v ) for v reachable from s form a breadth-first tree.

Lemma 22.1: G=(V,E):a directed or undirected graph. s:an arbitrary vertex : the shortest-path distance from s to v. Then for any Proof: s u v 1

Lemma 22.2: G=(V,E):a directed or undirected graph. s:an arbitrary vertex u.d: the distance from s to u computed by the algorithm Suppose that BFS is run on G from s. Then on termination, for each vertex v ∈ V, the value v.d computed by BFS satisfies v.d ≥ δ (s, v). Proof: By induction on the number Enqueue operations. Basis: when s is placed in Q. s.d =0 = δ(s, s) for all Induction Step: Consider a white vertex v discovered during the search from a vertex u. Inductive hypothesis implies u.d ≥ δ (s, u). By Lemma 22.1, v.d = u.d +1 ≥ δ(s, u) + 1 ≥ δ(s, v) From then on, v.d will not be changed again.

Lemma 22.3: Q:<v1,v2,…,vr>~ the queue when BFS executes on a graph G=(V,E). head tail Then and for i=1,2,…,r-1. Proof: By induction on the number of queue operations. Basis: when Q has only s. Induction Step: 1>: after dequeue: v2 becomes the new head in Q. by inductive hypothesis. 2>:after enqueue a new vertex v into the Q. Let vr+1 be v. neighbors Note that u’s adjacency list is being scanned and u is just removed. Thus, And The rest , for i=1,…,r-1, remain unaffected.

Thm 22.5: (Correctness of BFS) 1. During the execution of BFS on G=(V,E), BFS discovers every vertex v ∈ V that is reachable from s, and on termination v.d = δ(s, v) 2. For any vertex v ≠ s reachable from s, one of the shortest paths from s to v is the shortest path from s to v.π followed by the edge ( v.π, v).

from s to v.π then traversing the edge (v.π, v). Proof: If v unreachable from s, s.d  (s, v)=. By BFS, v is never discovered. By contradiction, suppose some vertex has a d value not equal to its shortest distance. Let v be the vertex with minimum (s, v) that has an incorrect d value. Let u be v’s immediate predecessor on the shortest path from s to v. So (s, v) = (s, u) +1. Because (s, u) < (s, v), we have u.d=(s, u). (*) Thus v.d > (s, v) = (s, u) + 1= u.d + 1. Consider the time when BFS chooses to dequeue u from Q. At this time v is either white, gray or black. Case 1: (v is white) line 15 set v.d = u.d + 1---contradicting (*) Case 2: (v is black) v is already not in Q, thus v.d  u.d --- contradicting (*) Case 3: (v is gray) v became gray while dequeuing some vertex w, which was removed earlier than u. Thus v.d= w.d +1 and w.d  u.d and so v.d  u.d + 1 – again a contradiction! Thus we conclude v.d = (s, v) for all v. All vertices reachable from s must be discovered. If v.π =u, then v.d = u.d +1. Thus, we can obtain a shortest path from s to v by taking a shortest path from s to v.π then traversing the edge (v.π, v).

Breadth-first trees: For a graph G=(V, E) with source s, define the predecessor subgraph of G as G’=(V’, E’), where V’ = { v  V: v.π ≠ NIL}  {s} and E’ = {(v.π, v): v  V’- {s}}. G’ is a BF tree if V’ consists of the vertices from s to v in G’ and, for all v in V’, there is a unique simple path from s to v, which is also a shortest path from s to v in G. Lemma 22. 6: When applied to a graph G=(V, E), procedure BFS construct π so that G’= (V’, E’) is a BF tree. Proof: Line 16 of BFS sets v.π =u iff (u, v) ∈ E and (s, v) < . Thus V’ consists of the vertices in V reachable from s. Since G’ forms a tree, it contains a unique path from s to each vertex in V’. By Thm 22.5, inductively, we have that every such path is a shortest path.

Print path演算法 可在執行過BFS演算法的圖上印出s到v的最短路徑。如無路徑也會印出沒有路徑的訊息。 Print-Path(G, s, v) if v == s print s elseif v.π == NIL print “no path from” s “to” v else Print-Path(G,s,v.π) print v 此演算法利用BFS建立的表格π,並利用遞迴的方式, 利用之前提過的BFS性質, (π[v],v)是某一條最短路徑上的一邊, 找出一條path並且列印出來。 Elementary Graph Algorithms

Depth-first search Nodes are initially white Nodes become gray when first discovered Nodes become black when they are done v.d records when v is first discovered v.f records when v is done u.d< u.f

(a) (b) 1/ 1/ 2/ (c) (d) 1/ 2/ 1/ 2/ 3/ 4/ 3/ u v w u v w x y z x y z Discovery time (a) u v w (b) u v w 1/ 1/ 2/ x y z x y z (c) u v w (d) u v w 1/ 2/ 1/ 2/ 3/ 4/ 3/ x y z x y z

(e) (f) 1/ 2/ 1/ 2/ 4/ 3/ 4/5 3/ (g) (h) 1/ 2/ 1/ 2/7 4/5 3/6 4/5 3/6 u v w (f) u v w 1/ 2/ 1/ 2/ B B 4/ 3/ 4/5 3/ x y z x y z (g) u v w (h) u v w 1/ 2/ 1/ 2/7 B B 4/5 3/6 4/5 3/6 x y z x y z

(i) (j) 1/ 2/7 1/8 2/7 4/5 3/6 4/5 3/6 (k) (l) 1/8 2/7 9/ 1/8 2/7 9/ u v w (j) u v w 1/ 2/7 1/8 2/7 B F B F 4/5 3/6 4/5 3/6 x y z x y z (k) u v w (l) u v w 1/8 2/7 9/ 1/8 2/7 9/ B F B C F 4/5 3/6 4/5 3/6 x y z x y z

(m) (n) 1/8 2/7 9/ 1/8 2/7 9/ 4/5 3/6 10/ 4/5 3/6 10/ (o) (o) 1/8 2/7 u v w (n) u v w 1/8 2/7 9/ 1/8 2/7 9/ B C F B C F B 4/5 3/6 10/ 4/5 3/6 10/ x y z x y z (o) u v w (o) u v w 1/8 2/7 9/ 1/8 2/7 9/12 B C B C F F B B 4/5 3/6 10/11 4/5 3/6 10/11 x y z x y z

(u,v) Back edges: if u is connected to an ancestor v in a depth- first tree. (eg self-loop) Forward edges: if u is connected to an descendant v in a depth-first tree. Cross edges: if u is not connected to an ancestor v in the same depth-first tree. OR if v is not connected to an ancestor u in the same depth-first tree. OR if u and v belong to different depth-first trees.

DFS演算法 DFS(G) for each vertex u∈ G.V do u.color = WHITE u.π = NIL time = 0 for each vertex u ∈ G.V if u.color == WHITE DFS-Visit(G,u) Elementary Graph Algorithms

DFS-Visit演算法 DFS-Visit(G, u) time = time+1 //u has just been discovered u.d = time u.color = GRAY for each v ∈ G.Adj[u] //explore edge (u,v) if v.color == WHITE v.π = u DFS-Visit(G, v) u.color = BLACK //DFS-Visit(G, u) is done time = time + 1 u.f = time Elementary Graph Algorithms

The running time of DFS is O(V+E) After execution of DFS, all nodes are colored black After execution of DFS, the edges( v.𝛑, v) form a collection of depth-first tree, called a depth-first forest.

Edge Classification 1. Tree edges( u, v ): u was discovered first using ( u,v ) 2. Back edges( u, v ): v is an ancestor of u in the DFS tree 3. Forward edges( u, v ): v is a descendent of u, not a tree edge 4. Cross edges( u, v ): Other edges Example In a depth-first search of an undirected graph, every edge is either a tree edge or a back edge

3/6 2/9 1/10 4/5 7/8 12/13 (a) 14/15 11/16 y z s x w v B C u t F (b) s 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ( s (z (y (x x) y) (w w) z) s) (t (v v) (u u) t)

(c) s C t B F z C u v B C y w C x

Thm 22.7: (Parenthesis theorem) In any DFS of a graph G=( V,E ), for any two vertices u and v, exactly one of the following 3 conditions holds: (1). The intervals [u.d, u.f] and [v.d, v.f] are disjoint, (2). The interval [u.d, u.f] is contained entirely within the interval [v.d, v.f], and u is a descendant of v in the depth-first tree, (3). or as above with v as a descendant of u

Pf: 1. If u.d < v.d case 1: v.d < u.f : So v is finished before finishing u. Thus (3) holds case 2: u.f < v.d u.d < u.f < v.d < v.f  (1) holds 2. If v.d < u.d: Similarly, by switching the roles of u and v v was discovered while u was still gray. v is a descendant of u, and all v’s outgoing edges are explored

Cor8: v is a proper descendant of vertex u in Cor8: v is a proper descendant of vertex u in the depth-first forest for a graph G iff u.d < v.d < v.f < u.f Thm9: (White-path theorem) In a DF forest of G=( V,E ), vertex v is a descendant of u iff at the time u.d that the search discovers u, v can be reached from u along a path consisting entirely of white vertices

Pf: “” v: descendant of u “” u.d < w.d, by the above cor. Assume at time u.d, v is reachable from u along a path of white vertices, but v does not become a descendant of u in DF tree Thus, u.d < v.d < w.f <= u.f Thm7 implies [v.d, v.f] is contained entirely in [u.d, u.f] By Cor8, v is a descendant of u. u.d < w.d, by the above cor. u w v Thus w is white at time u.d u w v Descendant of u w.f <= u.f v must be discovered after u is discovered, but before w is finished.

Thm 22.10: In a DFS of an undirected graph G, every edge of G is either a tree edge or a back edge Pf: Let and suppose u.d < v.d. Then v must be discovered and finished before finishing u If (u, v) is explored first in the direction from u to v, then (u, v) becomes a tree edge If (u, v) is explored first in the direction from v to u, then (u, v) is a back edge, since u is still gray at the time (u, v) is first explored

Topological sort 定義: A topological sort of a dag G=(V, E) is a linear ordering of all its vertices. (dag: Directed acyclic graph) 如 edge(u, v), u appears before v in the ordering undershorts socks pants shoes belt shirt tie jacket watch 11/16 12/15 6/7 1/8 2/5 3/4 17/18 13/14 9/10 socks undershorts pants shoes watch shirt belt tie jacket

TOPOLOGICAL-SORT(G): (V+E) 1. Call DFS(G) to compute finishing times v.f for each vertex v (V+E) 2. As each vertex is finished, insert it onto the front of a linked list O(1) 3. Return the linked list of vertices undershorts socks pants shoes belt shirt tie jacket watch 11/16 12/15 6/7 1/8 2/5 3/4 17/18 13/14 9/10 socks undershorts pants shoes watch shirt belt tie jacket 11/16 12/15 6/7 1/8 3/4 13/14 17/18 9/10 2/5

Lemma 22.11 A directed graph G is acyclic iff DFS(G) yields no back edges. pf:  Suppose there is a back edge (u,v), v is an ancestor of u. Thus there is a path from v to u and a cycle exists.  Suppose G has a cycle c. We show DFS(G) yields a back edge. Let v be the first vertex to be discovered in c, and (u,v) be the preceding edge in c. At time v.d, there is a path of white vertices from v to u. By the white-path thm., u becomes a descendant of v in the DF forest (u,v) is a back edge.

Thm 22.12 TOPOLOGICAL-SORT(G) produces a topological sort of G pf: Suppose DFS is run to determine finishing times for vertices. It suffices to show that for any pair of u,v , if there is an edge from u to v, then v.f< u.f. When (u,v) is explored by DFS(G), v cannot be gray. Therefore v must be either white or black. 1. If v is white, it becomes a descendant of u, so v.f < u.f 2. If v is black, then v.f < u.f

Strongly connected components: A strongly connected component of a directed graph G(V,E) is a maximal set of vertices U  V s.t. for every pair u, vU, u and v are reachable from each other. Given G=(V,E), define GT=(V,ET), where ET={(u,v): (v,u)E} Given a G with adjacency-list representation, it takes O(V+E) to create GT. G and GT have the same strongly connected components.

G: GT: 13/14 11/16 12/15 3/4 1/10 2/7 8/9 5/6 a b c d e f g h abe cd h

StronglyConnectedComponents(G) 1. Call DFS(G) to compute finishing times u.f for each vertex u 2. Compute GT 3. Call DFS(GT), but in the main loop of DFS, consider the vertices in order of decreasing u.f 4. Output the vertices of each tree in the depth-first forest of step 3 as a separate strongly connected component Time: (V+E)

Lemma 22.13: Let C and C’ be distinct strongly connected components in directed graph G=(V, E), let u, v in C and u’, v’ in C’, and suppose there is a path from u to u’ in in G. Then there cannot also be a path from v’ to v in G. Def: Let U  V, then we define d(U) = min { u.d } u U f (U) = max { u.f }

Lemma 22.14 Let C and C’ be distinct strongly connected components in directed graph G=(V, E). Suppose that there is an edge (u, v) in E, where u in C and v in C’. Then f (C) > f ( C’). pf: (1) If d(C) < d(C’): let x be the 1st discovered vertex in C. At time x.d all vertices in C and C’ are white. There is a path from x to all (white) vertices in C and to all vertices in C’: x~↝ u  v ~↝ w. All vertices in C and C’ are descendants of x. Thus x.f = f (C) > f(C’). (2) If d(C) > d(C’): let y be the 1st discovered vertex in C’. At time y.d all vertices in C’ are white and there is a path from y to all vertices in C’. I.e. all vertices in C’ are descendants of y. So y.f = f(C’). There cannot be a path from C’ to C. Thus any w in C has w.f > y.f and so f(C) > f(C’).

Corollary 22.15: Let C and C’ be distinct strongly connected components in directed graph G=(V, E). Suppose that there is an edge (u, v) in , where u in C and v in C’. Then f ( C ) < f ( C’ ). Pf: It is clear that (v, u) is in E. By the previous lemma we have f( C’ ) > f ( C ).

Thm 22.16 Strongly-Connected-Component(G) correctly computes the strongly connected components of a directed graph. pf: By induction on the number (k) of depth-first trees found in the DFS of GT, where each tree forms a strongly connected component. Basis: trivial for k=0. Inductive step: assume each of the first k DFS trees produced in line 3 is a SCC. Consider the (k+1)-st tree produced. Let u be the root of this tree and let u be in SCC C. Thus u.f = f ( C ) > f ( C’ ) for any other SCC C’ yet to be visited. Note we visit in decreasing finishing time.

All other vertices in C are descendant of u in its DFS. By inductive hypothesis and the previous Corollary 15 any edges in GT that leave C must be to SCC’s already visited. Thus, no vertex in any SCC other than C will be a descendant of u during the DFS of GT. Thus, the vertices of the DFS tree in GT that is rooted at u form exactly one SCC. 