HDU——T 4738 Caocao's Bridges
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
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.
1 2 7
2 3 4
3 1 4
3 2
1 2 7
2 3 4
0 0
4
#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的更多相关文章
- Hdu 4738 Caocao's Bridges (连通图+桥)
题目链接: Hdu 4738 Caocao's Bridges 题目描述: 有n个岛屿,m个桥,问是否可以去掉一个花费最小的桥,使得岛屿边的不连通? 解题思路: 去掉一个边使得岛屿不连通,那么去掉的这 ...
- HDU 4738 Caocao's Bridges(Tarjan求桥+重边判断)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4738——Caocao's Bridges——————【求割边/桥的最小权值】
Caocao's Bridges Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 4738 Caocao's Bridges 图--桥的判断模板
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4738 Caocao's Bridges
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU——4738 Caocao's Bridges
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdoj 4738 Caocao's Bridges【双连通分量求桥】
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4738 Caocao's Bridges(桥的最小权值+去重)
http://acm.hdu.edu.cn/showproblem.php?pid=4738 题目大意:曹操有一些岛屿被桥连接,每座都有士兵把守,周瑜想把这些岛屿分成两部分,但他只能炸毁一条桥,问最少 ...
随机推荐
- 初学javascript,写一个简单的阶乘算法当作练习
代码如下: <script> var a = prompt("请输入值"); function mul(a){ if(a==1){ return 1; } return ...
- clear---清除当前屏幕
clear命令用于清除当前屏幕终端上的任何信息.
- 紫书 习题 10-5 UVa 1213(01背包变形)
这里就是01背包多了一维物品个数罢了 记得不能重复所以有一层循环顺序要倒着来 边界f[0][0] = 1 #include<cstdio> #include<vector> # ...
- Spring Cloud分布式Session共享实践
通常情况下,Tomcat.Jetty等Servlet容器,会默认将Session保存在内存中.如果是单个服务器实例的应用,将Session保存在服务器内存中是一个非常好的方案.但是这种方案有一个缺点, ...
- [Recompose] Make Reusable React Props Streams with Lenses
If you hard-code a stream of props to target a specific prop, it becomes impossible to reuse that st ...
- Option可选值(一)
//: Playground - noun: a place where people can play import Cocoa class Person { var residence: Resi ...
- 简单记录一次REDO文件损坏报错 ORA-00333重做日志读取块出错
一.故障描写叙述 首先是实例恢复须要用到的REDO文件损坏 二.解决方法 1.对于非当前REDO或者当前REDO可是无活动事务使用下面CLEAR命令: 用CLEAR命令重建该日志文件SQL>al ...
- 2015上海网络赛 HDU 5475 An easy problem 线段树
题意就不说了 思路:线段树,维护区间乘积.2操作就将要除的点更新为1. #include<iostream> #include<cstdio> #include<cstr ...
- Weka中数据挖掘与机器学习系列之Weka Package Manager安装所需WEKA的附加算法包出错问题解决方案总结(八)
不多说,直接上干货! Weka中数据挖掘与机器学习系列之Weka系统安装(四) Weka中数据挖掘与机器学习系列之Weka3.7和3.9不同版本共存(七) 情况1 对于在Weka里,通过Weka P ...
- Docker -- 系统整洁之道 -- 1
在上文Docker – 系统整洁之道 – 0中已经对Docker是什么,安装Docker以及怎么运行一个简单的容器有了初步了解,这篇文章介绍Docker的一些命令和Docker镜像的使用及操作. 一些 ...