connects U, v Point, and then outputs the number of remaining bridges in the connected graph.Idea: Mark the bridge first Tarjan, then LCA to remove all the bridges on the path. Code:1#include 2#include 3#include 4#include 5#include 6#include 7#include 8#include Set>9#include Ten#include One using namespacestd; A - #defineN 100005 - the intN, M; - intDfn[n], low[n], time; - intDep[n]; - BOOLBrg[n]; + intFather[n]; - intBrg_num; + A structedge{ at intu, V, next; -}e[400005]; - - intCNT;
{ thescanf"%d%d",u,v); + G[u].push_back (v); - g[v].push_back (u); $ } $ intHead=0, cnt=0; - for(intI=1; i) - if(g[i].size () = =1) the { -Head=i;///find a starting pointWuyicnt++; the } - if(cnt>2)///If there are more than two points with a degree of 1 Wu { -Puts"NO"); About Continue; $ } -memset (Vis,0,sizeof(Vis)); - if(Head = =0) -Head=1;///no degree is 1, which is a ring
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.