Test instructions: To a diagram, want to make every two roads have two side phase, but special is the same side several times connected also is considered to be a side, now ask for at least also need to add a few sides to do analysis: hand owes not to see clearly is the same side can not be connected, need to go to heavy side, shrink point after the number of leaf node #include <stdio.h>
#include <string.h>
#include <algorithm>
usingnamespaceStd
ConstintMAXN = 1e5+5;
structedge{intV, Next;} E[MAXN];
intHEAD[MAXN], CNT;
voidAddedge (intUintV
{
E[CNT].V = v;
E[cnt].next = Head[u];
Head[u] = cnt++;
}
intLOW[MAXN], DFN[MAXN], Index;
intSTACK[MAXN], top;
intBELONG[MAXN], BNT;
intRU[MAXN];
BOOLuse[5005][5005];
voidInIt (intN
{
CNT = Index = top = BNT =0;
memset (use,0,sizeof(use));
for(intI=1; i<=n; i++)
{
Head[i] =-1;
Dfn[i] =0;
Ru[i] =0;
}
}
voidTarjan (intUintFather
{
intV
Low[u] = dfn[u] = ++index;
Stack[++top] = u;
for(intJ=head[u]; J! =-1; J=e[j].next)
{
v = e[j].v;
if(!dfn[v])
{
Tarjan (V, u);
Low[u] = min (Low[u], low[v]);
}
Else if(V! = father)
Low[u] = min (Low[u], dfn[v]);
}
if(Low[u] = = Dfn[u])
{
++BNT;
Do
{
v = stack[top--];
BELONG[V] = BNT;
}
while(U! = v);
}
}
intMain ()
{
intN, M;
while(SCANF ("%d%d", &n, &m)! = EOF)
{
intI, J, u, V;
InIt (N);
while(m--)
{
scanf"%d%d", &u, &v);
if(Use[u][v] = =false)
{
Addedge (U, v);
Addedge (V, u);
USE[U][V] = Use[v][u] =true;
}
}
Tarjan (1,1);
for(i=1; i<=n; i++)
for(J=head[i]; j!=-1; J=e[j].next)
{
if(Belong[i]! = belong[e[j].v])
{
ru[Belong[i]]++;
}
}
intAns =0;
for(i=1; i<=bnt; i++)
{
if(Ru[i] = =1)
ans++;
}
printf"%d\n", (ans+1) >>1);
}
return0;
}
E-redundant Paths-poj 3177 (shrinking points for leaf nodes)