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 题目大意:曹操有一些岛屿被桥连接,每座都有士兵把守,周瑜想把这些岛屿分成两部分,但他只能炸毁一条桥,问最少 ...
随机推荐
- 关于memset赋最值
出处[辗转山河弋流歌 by 空灰冰魂] blog.csdn.net/vmurder/article/details/46537613 memset(a, 0x3f, sizeof(a)) //int, ...
- iOS 全局修改UINavigation 后退按钮
将导航栏的后退按钮中的文字去掉一直是老大难问题,现在可以使用运行时机制,将后退按钮文字清空 创建UINavigationItem的category,直接上代码 .h文件 #import <UIK ...
- Spring Cloud学习笔记【五】Hystrix Dashboard监控面板
ystrix除了隔离依赖服务的调用以外,Hystrix 还提供了准实时的调用监控(Hystrix Dashboard),Hystrix 会持续地记录所有通过 Hystrix 发起的请求的执行信息,并以 ...
- UML 绘图关系
1 继承 子类继承父类 2 实现 实现类实现接口 3 依赖 (偶然.临时.比较弱关联) 类 A 使用了类 B,如果类 B 产生变化将会影响类A ...
- 九、 HBase SHELL、 JAVA 和 Thrift 客户端
HBase 由 Java 语言实现,同时他也是最主要最高效的客户端. 相关的类在org.apache.hadoop.hbase.client 包中.涵盖所有 增删改查 API . 主要的类包含: HT ...
- 为OLED屏添加GUI支持3:字库
为OLED屏添加GUI支持3:字库 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:WIN10 开发环境:MDK5.13 MCU:STM3 ...
- LeetCode -- 最大连续乘积子序列
问题描写叙述: 给定数组,找出连续乘积最大值的子序列.比如 0,-1,-3.-2.则最大连续乘积为6= (-3) * (-2) 实现思路此题与最大连续和的子序列问题相似,也可通过找到递推公式然后用DP ...
- WebForms简介
http://www.w3school.com.cn/aspnet/aspnet_intro.asp ASP.NET 是下一代 ASP,不是 ASP 的更新版本. https://docs.micro ...
- logAnalyzer日志管理系统配置实例
LogAnalyzer日志管理系统配置实例 上个月我写过一篇<利用EventlogAnalyzer分析Linux日志>一文深受大家喜欢,今天我再次为大家讲解Linux系统下的一款开源的日志 ...
- Firefox 浏览器有用的插件
1.Undo Closed Tabs Button或Undo Closed Tabs Button (revived) 恢复关闭的标签页 2.NetVideohunter Video Download ...