Question: poj 2553 the bottom of a graph
Question: the general meaning of this question is to give a directed graph, which requires a point with a degree of 0 after a strongly connected contraction point.
Analysis: Getting started Question: first, the point of contraction is strongly connected, and then the degree of output is 0. Then, the enumeration output is enough.
# Include <cstdio> # include <vector> # include <iostream> # include <stack> # include <cstring> using namespace STD; const int n = 25000; vector <int> G [N]; int pre [N], lowlink [N], sccno [N], dfs_clock, scc_cnt; // sccno [I] ID of the SCC image where I is located // Number of scc_cnt Unicom blocks stack <int> S; void DFS (INT U) {pre [u] = lowlink [u] = ++ dfs_clock; S. push (U); For (INT I = 0; I <G [u]. size (); I ++) {int v = G [u] [I]; If (! Pre [v]) {DFS (V); lowlink [u] = min (lowlink [u], lowlink [v]);} else if (! Sccno [v]) {lowlink [u] = min (lowlink [u], pre [v]) ;}} if (lowlink [u] = pre [u]) {scc_cnt ++; For (;) {int x = S. top (); S. pop (); sccno [x] = scc_cnt; If (x = u) Break ;}} void find_scc (int n) {dfs_clock = scc_cnt = 0; memset (sccno, 0, sizeof (sccno); memset (PRE, 0, sizeof (pre); For (INT I = 0; I <n; I ++) if (! Pre [I]) DFS (I);} int in [N], out [N]; int flag [N]; vector <int> ans; void workout (INT N) {memset (Out, 0, sizeof (out); memset (flag, 0, sizeof (FLAG); For (INT u = 0; U <n; U ++) {for (INT I = 0; I <G [u]. size (); I ++) {int v = G [u] [I]; // printf ("% d \ n ", U + 1, V + 1, sccno [u], sccno [v]); If (sccno [u]! = Sccno [v]) {out [sccno [u] + = 1 ;}}for (INT I = 1; I <= scc_cnt; I ++) {If (out [I] = 0) Flag [I] = 1 ;}for (INT I = 0; I <n; I ++) {If (flag [sccno [I]) ans. push_back (I + 1) ;}for (INT I = 0; I <ans. size (); I ++) {printf ("% d % C", ANS [I], I = (ans. size ()-1 )? '\ N': '');} ans. clear () ;}int main () {// freopen ("input.txt", "r", stdin); int n, m, T; while (~ Scanf ("% d", & N) {scanf ("% d", & M); For (INT I = 0; I <m; I ++) {int X, Y; scanf ("% d", & X, & Y); G [x-1]. push_back (Y-1);} find_scc (n); workout (n); For (INT I = 0; I <n; I ++) g [I]. clear () ;}return 0 ;}
Poj 2553 the bottom of a graph [the degree of output in the strongly connected graph is 0 points]