POJ 3177 redundant Paths (double unicom)

Source: Internet
Author: User

/******************************************************* title: Redundant Paths (POJ 2177) Link:http://poj.org/problem?id=3177algorithm: Double unicom + shrink point of thought: first find all the double unicom components, the components are shrunk to a point and then find all the points of a point, with these points plus a 2 can be ************************************************* *******/#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<iostream>#include<stack>using namespacestd;Const intmx=5005; Vector<int>G[mx];stack<int>s;intDFN[MX],LOW[MX];intBCC[MX],VS[MX];int inch[MX];intDfs_cut,bcc_cut;voidDfsintUintFA) {Dfn[u]=low[u]=++Dfs_cut; Vs[u]=1;    S.push (U); intp=1;///Go heavy     for(intI=0; I<g[u].size (); i++)    {        intv=G[u][i]; if(v==fa&&p) {p=0; Continue; }        if(!Vs[v])            {DFS (V,U); Low[u]=min (low[u],low[v]); }        Elselow[u]=min (low[u],dfn[v]); }        ///Pinch point    if(low[u]==Dfn[u]) {Bcc_cut++; intx;  while(1) {x=S.top ();            S.pop (); BCC[X]=Bcc_cut; if(X==u) Break; }    }}intMain () {intn,m; scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) g[i].clear (); Bcc_cut=dfs_cut=0;  while(m--)    {        intu,v; scanf ("%d%d",&u,&v);        G[u].push_back (v);    G[v].push_back (U); } DFS (1,-1);  for(intu=1; u<=n;u++)    {         for(intj=0; J<g[u].size (); j + +)        {            intv=G[u][j]; if(bcc[u]!=Bcc[v]) {                inch[bcc[u]]++; inch[bcc[v]]++; }        }    }    intans=0;  for(intI=1; i<=bcc_cut;i++)    {        if(inch[i]==2) ans++; } printf ("%d\n", (ans+1)/2);}

POJ 3177 redundant Paths (double unicom)

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.