The number of points after the contraction point with the input degree of 1.
If the number is 1, the number of points of the strongly connected component will be output.
Otherwise, 0 is output;
Code
/* Kosaraju algorithm, undirected graph strongly connected component, time complexity O (N + M) idea: Based on the deep traversal sequence of graph G, the point set that can be searched in the reverse graph of G is a strong Unicom component */# include <iostream> # include <cstring> using namespace STD; const int INF = 10009; // link table, where the even side is the source image and the odd side is the reverse graph struct node {int V, Ne;} edge [100009]; /* SCC indicates the number of strongly connected subgraphs. dfn indicates the deep traversal sequence (Reverse Order is the topological sorting of reverse graphs). vis indicates the access Mark, sum records the number of nodes for each strongly connected component */INT head [INF], dfn [INF], vis [INF], sum [INF], n, m, SCC, CNT = 1, Tol; void Adde (int u, int v) {edge [++ CNT]. V = V; edge [CNT]. ne = head [u]; head [u] = CNT;} void DFS (int K) {vis [k] = 1; for (INT I = head [k]; i! = 0; I = edge [I]. Ne) if (I & 1) = 0 &&! Vis [edge [I]. v]) DFS (edge [I]. v); dfn [++ tol] = K;} void NDfS (int K) {vis [k] = SCC, sum [SCC] ++; for (INT I = head [k]; I! = 0; I = edge [I]. Ne) if (I & 1 )&&! Vis [edge [I]. v]) NDfS (edge [I]. v);} void kosaraju () {for (INT I = 1; I <= N; I ++) if (! Vis [I]) DFS (I); memset (VIS, 0, sizeof vis); For (INT I = N; I> 0; I --) if (! Vis [dfn [I]) SCC ++, NDfS (dfn [I]);} int make () {int deg [INF] = {0 }; // returns the result of a reverse graph showing whether each strongly connected link has an exit degree for (INT I = 3; I <= CNT; I + = 2) {If (vis [edge [I]. v] = vis [edge [I ^ 1]. v]) continue; deg [vis [edge [I]. v] ++;} Int J, T = 0; For (INT I = 1; I <= SCC; I ++) if (deg [I] = 0) j = I, T ++; If (t = 1) return sum [J]; return 0 ;}int main () {int X, Y; cin> N> m; For (INT I = 1; I <= m; I ++) {CIN> x> Y; Adde (x, y ), ADDE (Y, x);} kosaraju (); cout <make (); Return 0 ;}
Poj 2186. Popular cows solution report