hdu4738(边双连通分量,桥)
Caocao's Bridges
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5595 Accepted Submission(s):
1757
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.
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.
Zhou Yu had to send to complete the mission. If Zhou Yu couldn't succeed any
way, print -1 instead.
1 2 7
2 3 4
3 1 4
3 2
1 2 7
2 3 4
0 0
4
/*
hdu4738
1.原图可能不联通 这时不需要派人去炸桥 直接输出 0
2.有重边
3.可能有权值为0的桥 但我们必须要有一个人去带炸弹啊 所以这是输出 1
*/
#include<iostream>
#include<cstdio>
#include<cstring> #define N 1001 using namespace std;
int n,m,cnt,ans,flag;
int head[N],dfn[N],low[N],fa[N];
struct edge{
int u,v,w,net;
}e[N*N*]; inline int read()
{
int x=,f=;char c=getchar();
while(c>''||c<''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} inline void add(int u,int v,int w)
{
e[++cnt].v=v;e[cnt].w=w;e[cnt].net=head[u];head[u]=cnt;
} void init()
{
memset(low,,sizeof low);memset(dfn,,sizeof dfn);
memset(fa,,sizeof fa);memset(head,,sizeof head);
memset(e,,sizeof e);cnt=flag=;
} void Tarjan(int u,int father)
{
dfn[u]=low[u]=++cnt;
for(int i=head[u];i;i=e[i].net)
{
int v=e[i].v;
if(i==father+) continue;
if(!dfn[v])
{
Tarjan(v,i);low[u]=min(low[u],low[v]);
if(low[v]>dfn[u]) ans=min(ans,e[i].w);
}
low[u]=min(low[u],dfn[v]);//注意
}
} int main()
{
freopen("ly.txt","r",stdin);
int x,y,z;
while()
{
init();
n=read();m=read();
if(!n && !m) break;
for(int i=;i<=m;i++)
{
x=read();y=read();z=read();
add(x,y,z);add(y,x,z);
}cnt=;
ans=0x3f3f3f3f;
for(int i=;i<=n;i++) if(!dfn[i]) flag++,Tarjan(i,-);
if(flag>){printf("0\n");continue;}
ans=ans==0x3f3f3f3f?-:ans;ans=ans==?:ans;
printf("%d\n",ans);
}
return ;
}
hdu4738(边双连通分量,桥)的更多相关文章
- Graph_Master(连通分量_A_双连通分量+桥)
hdu 5409 题目大意:给出一张简单图,求对应输入的m条边,第i-th条边被删除后,哪两个点不连通(u,v,u<v),若有多解,使得u尽量大的同时v尽量小. 解题过程:拿到题面的第一反应缩点 ...
- HDU4612 Warm up 边双连通分量&&桥&&树直径
题目的意思很简单,给你一个已经连通的无向图,我们知道,图上不同的边连通分量之间有一定数量的桥,题目要求的就是要你再在这个图上加一条边,使得图的桥数目减到最少. 首先要做的就是找出桥,以及每个点所各自代 ...
- HDU 3394 双连通分量 桥 Railway
第一个答案是统计图中桥的个数 如果一个点-双连通分量中边的个数大于点的个数那么这个块中所有的边都是冲突的,累加到第二个答案中去. #include <iostream> #include ...
- Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)【转】【修改】
一.基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成 ...
- 【HDU4612】 双连通分量求桥
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 题目大意:给你一个无向图,问你加一条边后最少还剩下多少多少割边. 解题思路:好水的一道模板题.先 ...
- (转)Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)
基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成多个 ...
- Tarjan算法应用 (割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)问题)(转载)
Tarjan算法应用 (割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)问题)(转载) 转载自:http://hi.baidu.com/lydrainbowcat/blog/item/2 ...
- POJ 3177 Redundant Paths (桥,边双连通分量,有重边)
题意:给一个无向图,问需要补多少条边才可以让整个图变成[边双连通图],即任意两个点对之间的一条路径全垮掉,这两个点对仍可以通过其他路径而互通. 思路:POJ 3352的升级版,听说这个图会给重边.先看 ...
- POJ 3352 Road Construction(边双连通分量,桥,tarjan)
题解转自http://blog.csdn.net/lyy289065406/article/details/6762370 文中部分思路或定义模糊,重写的红色部分为修改过的. 大致题意: 某个企业 ...
- hdoj 4612 Warm up【双连通分量求桥&&缩点建新图求树的直径】
Warm up Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Su ...
随机推荐
- 计算1+2+...+100之和<for循环的学习>
#include <stdio.h> /* 计算1+2+....+100 soulsjie 20170525 */ void main(){ int i; int s=0; for(i=0 ...
- 58. Spring Boot国际化(i18n)【从零开始学Spring Boot】
国际化(internationalization)是设计和制造容易适应不同区域要求的产品的一种方式.它要求从产品中抽离所有地域语言,国家/地区和文化相关的元素.换言之,应用程序的功能和代码设计考虑在不 ...
- String replaceAll-正则匹配-截取以指定字符开头,以指定字符结尾的字符串
scala代码块 截取以某个字符开头,以某个字符结尾的字符串 def main(args: Array[String]): Unit = { val s = "{{a61,a2,a3},{b ...
- Flask基础(3):session、flash、特殊装饰器、蓝图、路由正则匹配、上下文管理 & flask-session
Session: Flask 默认将 session 以加密的形式放到了浏览器的 cookie 中 Flask 的 session 就是一个字典,字典有什么方法 session 就有什么方法 flas ...
- 将[object Object]转换成json对象
这两天在做中英文双版的文件,页面根据语言读取不同的内容.js模板用的是ejs json文件: "components":{ "pages":{ "ho ...
- android开发里跳过的坑——listview不显示
在蓝牙回调接口public void onLeScan(BluetoothDevice device, int arg1, byte[] arg2)里面调用adpter.notifyDataSetCh ...
- Linux下汇编语言学习笔记45 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- TCP/IP学习笔记(4)------ICMP,ping,traceroute
IMCP协议介绍 当传送IP数据包发生错误--比如主机不可达,路由不可达等等,ICMP协议将会把错误信息封包,然后传送回给主机.给主机一个处理错误的机会,这 也就是为什么说建立在IP层以上的协议是可能 ...
- 动态演示冒泡排序java
动态演示冒泡排序java //冒泡排序是一种简单的交换排序,基本思路,从数列左边开始扫描元素,在扫描过程中依次对相邻元素进行比较,将较大元素后移. public class NumberSort { ...
- Ubuntu 16.04中XMind 8导致Java内存溢出的问题解决(硬盘卡死,桌面卡死)
XMind使用的是Java进行开发,如果出现内存溢出的问题,那么一定是桌面快捷方式的问题,解决方法是直接修改快捷方式里面的内容,修改如下: [Desktop Entry] Encoding=UTF-8 ...