I-caocao ' s bridges-hdu 4738 (for bridge)

Source: Internet
Author: User

Test instructions: There are some bridge links between Cao's boat, and now Zhou Yu wants to divide the connected ship into two parts, but he can only blow up a bridge, and there are soldiers guarding each bridge, asking how many soldiers he needs at least to blow up the bridge if not, output '- 1 ' NOTE: This problem has several pits, the first input bridge guard is 0 words also have to platoon a soldier if the first bridge is disconnected, you don't have to send the soldiers, direct output 0***************************************************** #include <stdio.h>
#include <string.h>
#include <algorithm>
usingnamespaceStd

ConstintMAXN = 1e3+5;
Const intoo = 1e9;

structedge{intV, used, Val, next;} e[maxn*maxn*2];
intHEAD[MAXN], CNT;
voidAddedge (intUintVintVal
{
if(val = =0) val =1;
E[CNT].V = v;
e[cnt].used =false;
E[cnt].val = val;
E[cnt].next = Head[u];
Head[u] = cnt++;
}

intLOW[MAXN], DFN[MAXN], Index;
intMin;

voidInIt (intN
{
CNT = Index =0;
Min = oo;
for(intI=0; i<=n; i++)
{
Head[i] =-1;
Dfn[i] =0;
}
}
voidTarjan (intU
{
Dfn[u] = low[u] = ++index;

for(intJ=head[u]; j!=-1; J=e[j].next)
{
if(e[j].used = =false)
{
intv = e[j].v;

e[j].used = e[j^1].used =true;

if(!dfn[v])
{
Tarjan (v);
Low[u] = min (Low[u], low[v]);

if(Low[v] > Dfn[u])
min = min (min, e[j].val);
}
Else
Low[u] = min (Low[u], dfn[v]);
}
}
}

intMain ()
{
intN, M;

while(SCANF ("%d%d", &n, &m), n+m)
{
intU, V, Val;

InIt (N);

while(m--)
{
scanf"%d%d%d", &u, &v, &val);
Addedge (U, V, Val);
Addedge (V, U, Val);
}

Tarjan (1);

for(intI=1; i<=n; i++)
{
if(Dfn[i] = =0)
Min =0;
}

if(Min = = oo)
printf"-1\n");
Else
printf"%d\n", Min);
}

return0; 

}

I-caocao ' s bridges-hdu 4738 (for bridge)

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.