1. after understanding the meaning of the question, you can find that the requested graph contains at least two different paths between any two points. Here, I made a mistake, I mistakenly thought that only a point with a simple pair of matching degrees of 1 can get the answer. The reason for this error is that there may be a degree> 1, but there is a bridge edge with its corresponding edge.
Although it is easy to think about, you can immediately find out that the key to the problem lies in the bridge edge (in fact, the question requires a dual-connected component)
2. Use Tarjan to find the bridge edge. The nature of the bridge edge: There are (u, v) Two Points U-> V, and dfn (u) <low [v];
3. others only have the number of nodes with the degree of 1 after the contraction point and the contraction point. Here is a tips: after deleting a bridge edge, the vertex in the graph is divided into a connected component, so as long as one DFS () can label all vertices
# Include <iostream> <br/> # include <queue> <br/> # include <string> <br/> # include <map> <br/> # include <Vector> <br/> # include <cstring> <br/> # include <cstdio> <br/> # include <cmath> <br/> # include <algorithm> <br/> using namespace STD; <br/> const int max = 10000*2 + 5, maxn = 5005, INF = 1 <30; <br/> int F, R; </P> <p> bool vis [Max]; <br/> int U [Max], V [Max], next [Max]; <br/> int first [maxn]; <br/> int L; </P> <p> int index; <br /> Int dfn [maxn], low [maxn]; <br/> int CNT; <br/> int belong [maxn]; </P> <p> struct edge {<br/> int U, V; <br/>}; <br/> edge e [Max]; <br/> int degree [maxn]; </P> <p> void Tarjan (int I) {<br/> Int J; <br/> dfn [I] = low [I] = ++ index; <br/> for (int e = first [I]; e! =-1; E = next [e]) {<br/> If (vis [e]) <br/> continue; <br/> vis [e] = vis [E ^ 1] = 1; <br/> J = V [E]; <br/> If (! Dfn [J]) {<br/> Tarjan (j); <br/> low [I] = min (low [I], low [J]); <br/>}< br/> else <br/> low [I] = dfn [J]; <br/>}</P> <p> void color (int I) {<br/> Int J; <br/> for (int e = first [I]; e! =-1; E = next [e]) {<br/> J = V [E]; <br/> If (vis [e]) <br/> continue; <br/> If (! Dfn [J]) {<br/> dfn [J] = 1; <br/> belong [J] = CNT; <br/> color (j ); <br/>}</P> <p> int main () <br/>{< br/> # ifndef online_judge <br/> freopen ("I .txt", "r", stdin ); <br/> # endif <br/> int V1, V2; <br/> int leaf; <br/> memset (first,-1, sizeof (first )); <br/> L = 0; <br/> scanf ("% d/N", & F, & R ); <br/> for (INT I = 0; I <r; I ++) {<br/> scanf ("% d/N", & V1, & V2); </P> <p> U [l] = V1; V [l] = V2; <br/> next [l] = first [V 1]; <br/> first [V1] = L ++; </P> <p> U [l] = V2; V [l] = V1; <br/> next [l] = first [V2]; <br/> first [V2] = L ++; <br/>}</P> <p> Index = CNT = 0; <br/> Tarjan (1 ); // indicates that at least one undirected edge exists between the two days. </P> <p> memset (VIS, 0, sizeof (VIS )); <br/> for (INT I = 1, J; I <= f; I ++) {<br/> for (int e = first [I]; e! =-1; E = next [e]) {<br/> J = V [E]; <br/> If (dfn [I] <low [J]) {<br/> vis [e] = vis [E ^ 1] = 1; <br/>}</P> <p> CNT = 0; <br/> memset (dfn, 0, sizeof (dfn); <br/> for (INT I = 1; I <= f; I ++) {<br/> If (! Dfn [I]) {<br/> ++ CNT; <br/> dfn [I] = 1; <br/> belong [I] = CNT; <br/> color (I); <br/>}</P> <p> L = 0; <br/> memset (VIS, 0, sizeof (VIS); <br/> for (INT I = 1, J; I <= f; I ++) {<br/> for (int e = first [I]; e! =-1; E = next [e]) {<br/> If (vis [e]) <br/> continue; <br/> vis [e] = vis [E ^ 1] = 1; <br/> J = V [E]; <br/> If (belong [I]! = Belong [J]) {<br/> E [l]. U = belong [I]; <br/> E [L ++]. V = belong [J]; <br/>}</P> <p> for (int e = 0; e <L; E ++) {<br/> ++ degree [E [e]. u]; <br/> ++ degree [E [e]. v]; <br/>}</P> <p> leaf = 0; <br/> for (INT I = 1; I <= CNT; I ++) {<br/> If (degree [I] = 1) <br/> ++ leaf; <br/>}</P> <p> printf ("% d/N", (INT) Ceil (double) leaf/2 )); <br/> return 0; <br/>}</P> <p>