E-redundant Paths-poj 3177 (shrinking points for leaf nodes)

Source: Internet
Author: User

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)

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.