Title [brush] [bridge] cut point and redundant paths

For the same between pastures, you may have two different roads

The question really should look carefully ah

 

// a problem, how to become a double-side link components 
 // Leaf >> +. 1. 1 
#include <cstdio> 
#include <the cstdlib> 
#include <Stack>
 the using  namespace STD; 
inline int Read () 
{ 
    int X = 0 ; char C = getchar ();
     the while (C < ' 0 ' || C> ' . 9 ' ) C = getchar ();
     the while (C> = ' 0 ' && C <= ' . 9 ' ) X = (X << . 3 ) + (x <<1)+c-'0',c=getchar();
    return x;
}
int n,m;
const int N=5003,M=10003;
int col[N],sum;

int tot=1,head[N]; 
int ev[M<<1],enx[M<<1];
void add(int u,int v)
{    ev[++tot]=v,enx[tot]=head[u],head[u]=tot;
    ev[++tot]=u,enx[tot]=head[v],head[v]=tot;    }

int dfn[N],low[N],cnt;
stack <int > S;
 void Tarjan ( int RT, int pre) // strong even deflation point 
{ 
    DFN [RT] = Low [RT] ++ = CNT; 
    s.push (RT); 
    
    for ( int I = head [RT] ; I; I = ENX [I])
         IF ((pre ^ . 1 !) = I) // for the same between pastures may have two different paths 
        {
             IF (! DFN [EV [I]]) 
                Tarjan (EV [I], I);     
            Low [RT] = min (Low [RT], Low [EV [I]]); 
        } 
    IF (DFN [RT] == Low [RT]) 
    { 
        COL [RT]=++sum;
        while(s.top() !=rt)
            col[s.top() ]=sum,s.pop() ;
        s.pop() ;
    }    
}

int in[N];
int main()
{
    n=read(),m=read();
    for(int i=1;i<=m;i++)
        add(read(),read());
    for(int i=1;i<=n;i++)
        if(!dfn[i])
            tarjan(i,0);
    
    int ans=0;
    for(int i=2;i<tot;i+=2)
        if(col[ev[i]]!=col[ev[i|1]] )
            in[col[ev[i]]]++,in[col[ev[i|1]]]++;
    for(int i=1;i<=sum;i++)
        if(in[i]==1) ans++; 
    printf("%d\n",ans+1>>1);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/xwww666666/p/11755478.html