Two nodes
Time Limit: 24000/12000 MS (Java/others) memory limit: 65535/32768 K (Java/Others)
Total submission (s): 1137 accepted submission (s): 333
Problem descriptionsuppose that G is an undirected graph, and the value
StabIs defined as follows:
Among the expression, g-I,-J is the remainder after removing node I, node J and all edges that are directly relevant to the previous two nodes.
CntcompentIs the number of connected components of X independently.
Thus, given a certain undirected graph G, you are supposed to calculating the value
Stab.
Inputthe input will contain in the description of several graphs. for each graph, the description consist of an integer N for the number of nodes, an integer m for the number of edges, and m pairs of integers for edges (3 <= n, m <= 5000 ).
Please note that the endpoints of edge is marked in the range of [0, N-1], and input cases ends with EOF.
Outputfor each graph in the input, you should output the value
Stab.
Sample input4 50 11 22 33 00 2
Sample output2: an undirected graph with n knots and m edges. the maximum number of connected components left at two knots can be deleted. Idea: The question is limited to 12 ms. You don't have to think about it. Let's say it's violent .. Enumerate the first node to be deleted, and then obtain the number of left cut points and their sons (that is, the number of connected components after the cut point is deleted). The maximum value is continuously updated. The idea is very simple, and the code is detailed many times, wa... Code:
1 # include <cstdio> 2 # include <cstring> 3 # include <iostream> 4 # include <algorithm> 5 # include <vector> 6 # include <queue> 7 using namespace std; 8 9 # define n 500510 11 vector <int> ve [N]; 12 INT dfn [N], low [N], visited [N]; 13 int GD [N]; 14 int n, m, dfn_clock, lt_num, root, son, del; 15 16 void Tarjan (int u, int FA) {17 if (u = del) return; // Delete the first vertex 18 int I, j, k; 19 dfn [u] = low [u] = dfn_clock ++; 20 visited [U] = 1; 21 for (I = 0; I <ve [u]. size (); I ++) {22 int v = ve [u] [I]; 23 if (V = del) continue; // Delete the first vertex 24 if (V = FA) continue; 25 if (! Visited [v]) {26 Tarjan (v, U); 27 low [u] = min (low [u], low [v]); 28 If (u = root) son ++; 29 else if (low [v]> = dfn [u]) Gd [u] ++; // Number of sons corresponding to the cut point + 1 30} 31 else low [u] = min (low [u], dfn [v]); 32} 33} 34 35 main () 36 {37 int I, J, K, X, Y; 38 While (scanf ("% d", & N, & M) = 2) {39 for (I = 0; I <= N; I ++) ve [I]. clear (); 40 while (M --) {41 scanf ("% d", & X, & Y); 42 ve [X]. push_back (y); 43 ve [Y]. push_back (x); 44} 45 int ans =-1; 46 for (I = 0; I <n; I ++ ){// Enumerate the first deleted vertex 47 memset (visited, 0, sizeof (visited); 48 memset (dfn, 0, sizeof (dfn); 49 memset (Gd, 0, sizeof (GD); 50 visited [I] = 1; 51 dfn_clock = lt_num = Son = 0; 52 del = I; 53 int Maxson = 0; 54 55 for (j = 0; j <n; j ++) {// find another vertex to be deleted from the left. The other vertex must be the cut vertex 56 If (! Visited [J]) {57 lt_num ++; 58 // visited [J] = 1; 59 root = J; 60 Tarjan (J,-1 ); 61 Maxson = max (Maxson, son); 62 son = 0; 63} 64} 65 if (lt_num = N-1) lt_num --; // wa many times here, try this data: 5 0 66 for (j = 0; j <n; j ++) ans = max (ANS, GD [J] + lt_num ); 67 ans = max (ANS, Maxson + lt_num-1); 68} 69 printf ("% d \ n", ANS); 70} 71}
Cut Point of HDU 4587 undirected graph