http://acm.hdu.edu.cn/showproblem.php?pid=4738

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

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
 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6143 6142 6141 6140 6139 
 
题意:炸去代价最小的一个桥,使图不连通
所以 若原图不连通,则输出0,,若桥上的兵数为0则输出1 ,毕竟还需要人去炸,,若无割边,就输出-1
 #include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; const int INF(0x7fffffff);
const int N(+);
const int M(N*N);
int n,m,u,v,w,ans,num;
int head[N],sumedge;
struct Edge
{
int to,next,w;
Edge(int to=,int next=,int w=) :
to(to),next(next),w(w){}
}edge[M<<]; void ins(int from,int to,int w)
{
edge[++sumedge]=Edge(to,head[from],w);
head[from]=sumedge;
} int dfn[N],low[N],tim;
void DFS(int now,int pre)
{
low[now]=dfn[now]=++tim;
int sumtredge=;
for(int i=head[now];i!=-;i=edge[i].next)
if((i^)!=pre)
{
int go=edge[i].to;
if(!dfn[go])
{
sumtredge++;
DFS(go,i);
if(low[go]>dfn[now])
ans=min(ans,edge[i].w);
low[now]=min(low[now],low[go]);
}
else low[now]=min(low[now],dfn[go]);
}
} int main()
{
for(;;)
{
scanf("%d%d",&n,&m);
if(!n&&!m) break;
sumedge=-;num=;ans=INF;tim=;
memset(head,-,sizeof(head));
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&w);
ins(u,v,w); ins(v,u,w);
}
for(int i=;i<=n;i++)
if(!dfn[i]) DFS(i,-),num++;
if(num>) puts("");
else if(!ans) puts("");
else if(ans==INF) puts("-1");
else printf("%d\n",ans);
}
return ;
}

HDU——T 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

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

  8. hdoj 4738 Caocao's Bridges【双连通分量求桥】

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

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

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

随机推荐

  1. ArchLinux 音乐播放客户端ncmpcpp和服务端mpd的配置

    Ncmcpp是一个mpd客户端,它提供了很多方便的操作 MPD是一个服务器-客户端架构的音频播放器.功能包括音频播放, 播放列表管理和音乐库维护,所有功能占用的资源都很少. --取自 wiki.arc ...

  2. Perl模块利用CPAN在线安装自动化

    需要解决2个问题: 1.  如何与CPAN交互:利用perl –MCPAN –e ‘install 模块’ 2.  如何安装指定的版本:作者/模块-版本.tar.gz How to install a ...

  3. 【Fiddler】使用fiddler抓取指定浏览器的包

    参考资料:http://blog.csdn.net/sufubo/article/details/49331705 使用fiddler抓取不到浏览器的包时常用的解决办法: 1.必须先打开Fiddler ...

  4. 20180929 北京大学 人工智能实践:Tensorflow笔记06

    入戏 需要修改成如下: (完)

  5. 紫书 习题 10-4 UVa 1644(素数筛)

    素数筛没什么好说的 #include<cstdio> #include<vector> #include<cstring> #define REP(i, a, b) ...

  6. C#开发奇技淫巧二:根据dll文件加载C++或者Delphi插件

    原文:C#开发奇技淫巧二:根据dll文件加载C++或者Delphi插件 这两天忙着把框架改为支持加载C++和Delphi的插件,来不及更新blog了.      原来的写的框架只支持c#插件,这个好做 ...

  7. Maven学习总结(21)——Maven常用的几个核心概念

    在使用Maven的过程中,经常会遇到几个核心的概念,准确的理解这些概念将会有莫大的帮助. 1. POM(Project Object Model)项目对象模型 POM 与 Java 代码实现了解耦,当 ...

  8. storm 消息确认机制及可靠性

    worker进程死掉 在一个节点 kill work进程 比方 kill 2509  对work没有影响 由于会在其它节点又一次启动进程运行topology任务 supervisor进程死掉 supe ...

  9. Android禁止ViewPager的左右滑动

    转载请注明出处:http://blog.csdn.net/allen315410/article/details/40744287 有时候在开发中会遇到一些"诡异"的要求,比方在V ...

  10. 123.static静态函数与类模板

    #include <iostream> using namespace std; //静态函数没有this指针,无需创建对象就可以直接调用 template<class T> ...