The largest clique high-connectivity component of ultraviolet A 11324 contraction point to construct a DAG

Source: Internet
Author: User

Question: The largest clique of the ultraviolet (a) 11324
Start at a certain point and find the maximum number of nodes that can be walked at a time

Analysis:
Tarjan calculates GCC, and then constructs a new graph. The new graph is a dag. For the Dag, use DP to find the longest path. The DP transition equation is DP [x] = size [x] + max (DP [y]). After the point is scaled down, the edge X to Y is displayed. You can simply perform a memory search, specific implementationCode

 

# Include <iostream> # include <cstring> # include <cstdio> # include <vector> using namespace STD; const int maxn = 1005; const int maxm = 50005; # define debug puts ("here"); int dfn [maxn], low [maxn], stack [maxn], Father [maxn], bcnt, top, depth; bool instack [maxn]; int po [maxn], Tol, n, m; int ID [maxn]; int DP [maxn]; int sum [maxn]; vector <int> VEC [maxn]; struct node {int y, next;} edge [maxm]; void add (int x, int y) {edge [++ tol]. y = y; edge [tol]. next = po [X]; po [x] = tol;} void DFS (int x) {// Recursive Implementation of Tarjan Algorithm Low [x] = dfn [x] = ++ depth; instack [x] = true; stack [++ top] = x; int y; for (INT I = po [X]; I; I = edge [I]. next) {Y = edge [I]. y; If (! Dfn [y]) {DFS (y); low [x] = min (low [X], low [y]);} else if (instack [y]) low [x] = min (low [X], dfn [y]);} If (low [x] = dfn [x]) {++ bcnt; do {Y = stack [top --]; instack [y] = false; father [y] = bcnt;} while (X! = Y) ;}} void Tarjan () {memset (low, 0, sizeof (low); memset (dfn, 0, sizeof (dfn )); top = bcnt = depth = 0; For (INT I = 1; I <= N; I ++) if (! Dfn [I]) DFS (I);} int F (INT X) {// evaluate the longest path of Dag if (DP [x]) return DP [X]; int ans = 0; For (INT I = 0; I <(INT) VEC [X]. size (); I ++) {// starting from all the edges of X, find the maximum path int y = VEC [x] [I]; ans = max (ANS, f (y); // transfer equation} DP [x] = ans + sum [X]; return DP [X];} void DAG () {memset (ID, 0, sizeof (ID); memset (sum, 0, sizeof (SUM); memset (DP, 0, sizeof (DP); For (INT I = 1; I <= N; I ++) VEC [I]. clear (); For (INT x = 1; x <= N; X ++) {// create a new graph for (Int J = po [X]; j = ed GE [J]. Next) {int y = edge [J]. Y; If (father [x]! = Father [y]) {VEC [Father [x]. push_back (father [y]); Id [Father [y] ++;} sum [Father [x] ++; // count the number of nodes of all source images contained by the node after each contraction} int ans = 0; For (INT I = 1; I <= bcnt; I ++) if (! Id [I]) ans = max (f (I), ANS); cout <ans <Endl;} int main () {freopen ("sum. in "," r ", stdin); int ncase; CIN> ncase; while (ncase --) {CIN> N> m; int X, Y; memset (PO, 0, sizeof (PO); Tol = 0; while (M --) {scanf ("% d", & X, & Y ); add (x, y);} Tarjan (); DAG ();} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.