[Question]: A undirected connected graph is displayed. How many edges can be added to an edge-a two-way connected graph?
[Idea]: The same as 3352, find the edge-double connected component, shrink point becomes a tree, find this tree in the degree of 1 point num result is (num-1) /2;
But !! The difference here is that there is a duplicate edge. When there is a duplicate edge, the two points of different low values may belong to the same edge-double connected component.
Therefore, you must remove the duplicate edge when composing the image!
1 # include <iostream> 2 # include <stdio. h> 3 # include <string. h> 4 # include <stack> 5 # include <vector> 6 using namespace STD; 7 8 int pre [1002], low [1002], n, adj [1002], num, C, Du [1002], count1 [5005]; 9 10 11 struct E 12 {13 int to; 14 int next; 15} edge [500000]; 16 17 18 stack <int> S; 19 20 void add (int A, int B) 21 {22 count1 [a] ++; 23 edge [num]. to = B; 24 edge [num]. next = adj [a]; 25 adj [a] = num ++; 26} 27 28 Int DFS (int u, int FA) 29 {30 int I, V, lowv; 31 pre [u] = low [u] = C ++; 32 For (I = adj [u]; I! =-1; I = edge [I]. Next) 33 {34 int V; 35 V = edge [I]. To; 36 IF (V! = Fa & Pre [v] <PRE [u]) 37 {38 If (! Pre [v]) 39 {40 lowv = DFS (v, U); 41 low [u] = min (low [u], lowv ); 42} 43 else if (pre [v] & V! = FA) 44 Low [u] = min (low [u], pre [v]); 45} 46} 47 return low [u]; 48} 49 50 int main () 51 {52 int A, B, M, I, V; 53 While (~ Scanf ("% d", & N, & M) 54 {55 // printf ("fddfd"); 56 memset (adj,-1, sizeof (adj); 57 memset (count1, 0, sizeof (count1); 58 num = 0; 59 While (M --) 60 {61 scanf ("% d", & A, & B); 62 for (I = adj [a]; I! =-1; I = edge [I]. next) 63 If (edge [I]. to = B) 64 break; 65 if (I =-1 | count1 [a] = 0) // determine if it is a duplicate edge. Do not add 66 {67 // printf ("11 okok \ n"); 68 Add (A, B ); 69} 70 71 for (I = adj [B]; I! =-1; I = edge [I]. next) 72 If (edge [I]. to = A) 73 break; 74 if (I =-1 | count1 [B] = 0) 75 {76 // printf ("22 okok \ n"); 77 add (B, A); 78} 79 80} 81 C = 1; 82 83 memset (PRE, 0, sizeof (pre); 84 For (INT I = 1; I <= N; I ++) 85 if (pre [I] = 0) 86 DFS (I,-1); 87 88 memset (DU, 0, sizeof (DU); 89 90 91 92 for (INT u = 1; U <= N; U ++) 93 {94 for (I = adj [u]; I! =-1; I = edge [I]. Next) 95 {96 int V; 97 V = edge [I]. To; 98 If (low [u]! = Low [v]) 99 {100 DU [low [u] ++; 101 du [low [v] ++; 102} 103} 104 // printf ("% d \ n", U, low [u]); 105} 106 int ans = 0; 107 for (INT I = 0; I <= N; I ++) 108 If (Du [I]/2 = 1) 109 ans ++; 110 111 printf ("% d \ n", (ANS + 1)/2); 112 113} 114 return 0; 115}