Caocao's Bridges

              Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
                    Total Submission(s): 5050    Accepted Submission(s): 1584

Problem Description
Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. But he wouldn't give up. Caocao's army still was not good at water battles, so he came up with another idea. He built many islands in the Changjiang river, and based on those islands, Caocao's army could easily attack Zhou Yu's troop. Caocao also built bridges connecting islands. If all islands were connected by bridges, Caocao's army could be deployed very conveniently among those islands. Zhou Yu couldn't stand with that, so he wanted to destroy some Caocao's bridges so one or more islands would be seperated from other islands. But Zhou Yu had only one bomb which was left by Zhuge Liang, so he could only destroy one bridge. Zhou Yu must send someone carrying the bomb to destroy the bridge. There might be guards on bridges. The soldier number of the bombing team couldn't be less than the guard number of a bridge, or the mission would fail. Please figure out as least how many soldiers Zhou Yu have to sent to complete the island seperating mission.
 
Input
There are no more than 12 test cases.

In each test case:

The first line contains two integers, N and M, meaning that there are N islands and M bridges. All the islands are numbered from 1 to N. ( 2 <= N <= 1000, 0 < M <= N2 )

Next M lines describes M bridges. Each line contains three integers U,V and W, meaning that there is a bridge connecting island U and island V, and there are W guards on that bridge. ( U ≠ V and 0 <= W <= 10,000 )

The input ends with N = 0 and M = 0.

 
Output
For each test case, print the minimum soldier number Zhou Yu had to send to complete the mission. If Zhou Yu couldn't succeed any way, print -1 instead.
 
Sample Input
3 3
1 2 7
2 3 4
3 1 4
3 2
1 2 7
2 3 4
0 0
 
Sample Output
-1 4
 
题目:
周宇要炸调曹操的岛屿网络,是他们不相连,但是他只有一枚炸弹,所以他只能摧毁一座桥。周宇必须派一个人带炸弹来摧毁这座桥。桥上可能有守卫。轰炸队的士兵数量不能少于桥梁的守卫人数,否则任务将失败。请找出至少有多少士兵周宇要送到岛分离任务完成。
思路:
求出割边,求出边权最小的割边。如果没有割边,则无法完成任务,输出-1,如果割边不为1,我们求最小的割边的边权
有特殊情况要判断
1.这个图不一定是连通的,这样我们就不用去炸了
2.这个桥上可能没有人,但是我们还是要派一个人去炸桥
3.这个图没有割点,那就无法完成任务,输出-1
代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 1000010
using namespace std;
int n,m,x,y,z,s,tim,tot,ans=N;
int dfn[N],low[N],vis[N],head[N],cut_edge[N],cut_point[N];
struct Edge
{
    int from,to,next,dis;
}edge[N];
int read()
{
    ,f=; char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
int add(int x,int y,int z)
{
    tot++;
    edge[tot].to=y;
    edge[tot].dis=z;
    edge[tot].next=head[x];
    head[x]=tot;
}
int  tarjan(int now,int pre)
{
    ; bool boo=false; vis[now]=true;
    dfn[now]=low[now]=++tim;
    for(int i=head[now];i;i=edge[i].next)
    {
        int t=edge[i].to;
        )==i) continue;
        if(!dfn[t])
        {
            sum++;tarjan(t,i);
            low[now]=min(low[now],low[t]);
            if(low[t]>dfn[now]) ans=min(ans,edge[i].dis);
        }
        else
          low[now]=min(low[now],dfn[t]);
    }
    s++;
}
void clean()
{
    ans=N,tim=,tot=,s=;
    memset(dfn,,sizeof(dfn));
    memset(low,,sizeof(low));
    memset(vis,,sizeof(vis));
    memset(head,,sizeof(head));
    memset(cut_edge,,sizeof(cut_edge));
}
int main()
{
    )
    {
        n=read(),m=read();
        clean();
        &&m==) break;
        ;i<=m;i++)
         x=read(),y=read(),z=read(),add(x,y,z),add(y,x,z);
        tarjan(,);
        if(s<n) printf("0\n");
        else if(ans==N) printf("-1\n");
        ) printf("1\n");
        else printf("%d\n",ans);
    }
    ;
}

HDU——4738 Caocao's Bridges的更多相关文章

  1. Hdu 4738 Caocao's Bridges (连通图+桥)

    题目链接: Hdu 4738 Caocao's Bridges 题目描述: 有n个岛屿,m个桥,问是否可以去掉一个花费最小的桥,使得岛屿边的不连通? 解题思路: 去掉一个边使得岛屿不连通,那么去掉的这 ...

  2. HDU 4738 Caocao's Bridges(Tarjan求桥+重边判断)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. HDU 4738——Caocao's Bridges——————【求割边/桥的最小权值】

     Caocao's Bridges Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  4. hdu 4738 Caocao's Bridges 图--桥的判断模板

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. HDU 4738 Caocao's Bridges

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 4738 Caocao's Bridges(桥的最小权值+去重)

    http://acm.hdu.edu.cn/showproblem.php?pid=4738 题目大意:曹操有一些岛屿被桥连接,每座都有士兵把守,周瑜想把这些岛屿分成两部分,但他只能炸毁一条桥,问最少 ...

  8. hdu 4738 Caocao's Bridges (tarjan求桥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题目大意:给一些点,用一些边把这些点相连,每一条边上有一个权值.现在要你破坏任意一个边(要付出相 ...

  9. 【HDU 4738 Caocao's Bridges】BCC 找桥

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题意:给定一个n个节点m条边的无向图(可能不连通.有重边),每条边有一个权值.判断其连通性,若双 ...

随机推荐

  1. zabbix详细介绍及其自动动态发现

    zabbix3.2.1 第1章 安装 1.1 查看系统环境 [root@centos7-2 ~]# [root@centos7-2 ~]# hostname -I 10.0.0.10 172.16.1 ...

  2. JQ 获取Table的td 值

    <script type="text/javascript"> function SetTable() { $("#myTab table").ea ...

  3. ASP.NET MVC5 之 分部页

    1.分部页 _PartialPage.cshtml @model List<string> <a>完美世界</a> @foreach (var item in Mo ...

  4. 数据结构之顺序队列(C实现)

    一.队列是什么 队列是一种可以实现“先进先出”的存储结构. 队列通常可以分为两种类型: 一.顺序队列,采用顺序存储,当长度确定时使用. 顺序队列又有两种情况: ①使用数组存储队列的称为静态顺序队列. ...

  5. FJOI2019退役记

    day1 不意外地一点都不紧张,早就感觉没有机会了吧 进场非常从容地读完了三道题,开始写t1暴力,接着就开始自闭,不知道该开t2还是t3,最后先开了t3,想了想这不是选两条不相交的链吗,这个暴力不是林 ...

  6. CSS之背景设置、字体设置、文本设置

    <html> <head> <meta charset="utf-8"> <title>单行文本框与多行文本框</title& ...

  7. 全面学习ORACLE Scheduler特性(11)使用Job Classes

    六.使用Job Classes Job Classes 相当于创建了一个job组,DBA可以将那些具有相同特性的job,统统放到相同的Job Classes中,然后通过对Job Class应用ORAC ...

  8. Spark SQL概念学习系列之Spark SQL入门(八)

    前言 第1章   为什么Spark SQL? 第2章  Spark SQL运行架构 第3章 Spark SQL组件之解析 第4章 深入了解Spark SQL运行计划 第5章  测试环境之搭建 第6章 ...

  9. Hbase源码分析:server端RPC

    server端rpc包括master和RegionServer.接下来主要梳理一下,master和regionserver中有关rpc创建,启动以及处理的过程. 1,server rpc的初始化过程 ...

  10. go 语言开发环境的安装与配置

    go 语言开发环境的安装与配置 编辑器选择 一直以来都是用sublime,但是听说sublime对于golang的插件支持并不是特别完善,并且VS Code只要在自身所带的扩展商店里安装go插件就可以 ...