HDU 4738 Caocao's Bridges
Caocao's Bridges
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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 <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#pragma comment(linker, "/STACK:10240000000000,10240000000000")
using namespace std;
typedef long long LL ;
const int Max_N= ;
struct Edge{
int v ;
int w ;
int next ;
};
Edge edge[Max_N*Max_N] ;
int id ,indx ;
int vec[Max_N] ,dfn[Max_N] ,low[Max_N] ;
bool visited[Max_N];
int grid[Max_N][Max_N] ;
vector<int>brige ;
void add_edge(int u ,int v ,int w){
edge[id].v=v ;
edge[id].w=w ;
edge[id].next=vec[u] ;
vec[u]=id++ ;
} void init(){
id= ;
indx= ;
memset(vec,-,sizeof(vec)) ;
memset(visited,,sizeof(visited)) ;
memset(grid,,sizeof(grid)) ;
memset(dfn,,sizeof(dfn)) ;
brige.clear() ;
} void dfs(int u ,int father){
dfn[u]=low[u]=++indx ;
for(int e=vec[u];e!=-;e=edge[e].next){
int v=edge[e].v ;
int w=edge[e].w ;
if(!dfn[v]){
dfs(v,u) ;
low[u]=Min(low[u],low[v]) ;
if(low[v]>dfn[u]&&grid[u][v]==)
brige.push_back(w) ;
}
else if(v!=father)
low[u]=Min(low[u],dfn[v]) ;
}
} int Dot ;
void dfs(int u){
visited[u]= ;
Dot++ ;
for(int e=vec[u];e!=-;e=edge[e].next){
int v=edge[e].v ;
if(!visited[v])
dfs(v) ;
}
} int main(){
int N ,M ,u ,v ,w ;
while(scanf("%d%d",&N,&M)!=EOF){
if(N==&&M==)
break ;
init() ;
while(M--){
scanf("%d%d%d",&u,&v,&w) ;
add_edge(u,v,w) ;
add_edge(v,u,w) ;
grid[u][v]++ ;
grid[v][u]++ ;
}
Dot= ;
dfs() ;
if(Dot!=N){
puts("") ;
continue ;
}
for(int i=;i<=N ;i++){
if(!dfn[i])
dfs(i,-) ;
}
if(brige.size()==){
puts("-1") ;
continue ;
}
sort(brige.begin(),brige.end()) ;
printf("%d\n",brige[]==?:brige[]) ;
}
return ;
}
HDU 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 (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) ...
- hdu 4738 Caocao's Bridges(桥的最小权值+去重)
http://acm.hdu.edu.cn/showproblem.php?pid=4738 题目大意:曹操有一些岛屿被桥连接,每座都有士兵把守,周瑜想把这些岛屿分成两部分,但他只能炸毁一条桥,问最少 ...
- hdu 4738 Caocao's Bridges (tarjan求桥)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题目大意:给一些点,用一些边把这些点相连,每一条边上有一个权值.现在要你破坏任意一个边(要付出相 ...
- 【HDU 4738 Caocao's Bridges】BCC 找桥
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题意:给定一个n个节点m条边的无向图(可能不连通.有重边),每条边有一个权值.判断其连通性,若双 ...
随机推荐
- Android 使用AIDL调用外部服务
好处:多个应用程序之间建立共同的服务机制,通过AIDL在不同应用程序之间达到数据的共享和数据相互操作, 本文包括: 1 .创建AIDL 服务端.2 .创建AIDL 客户端. 3.客户端调用服务端提供的 ...
- 【架构】生成全局唯一ID的3个思路,来自一个资深架构师的总结
标识(ID / Identifier)是无处不在的,生成标识的主体是人,那么它就是一个命名过程,如果是计算机,那么它就是一个生成过程.如何保证分布式系统下,并行生成标识的唯一与标识的命名空间有着密不可 ...
- SVN 获取源码一直没绿色打勾的标识原因。
左天晚上,找了一晚的原因,各种尝试,SVN 获取源码一直没绿色打勾的标识原因. 后来在百度知道发现了这个原因,是因为我没有使用的是EXPORT,这样只是导出没有代码关联, 只要 使用checkout就 ...
- 转:Why SeaJS
原文地址:http://chaoskeh.com/blog/why-seajs.html Why SeaJS 前言 本文主要面向刚接触 SeaJS 的同学.文章会先提出传统 Javascript 开发 ...
- [转].net 使用NPOI或MyXls把DataTable导出到Excel
本文转自:http://www.cnblogs.com/yongfa365/archive/2010/05/10/NPOI-MyXls-DataTable-To-Excel-From-Excel.ht ...
- Java 读Properties
import java.io.*; import java.util.Properties; public class Study { public static void main(String[] ...
- 【python】环境变量的配置
在windows下安装python之后,系统并不会自动添加相应的环境变量.此时不能在命令行直接使用python命令. 1.首先需要在系统中注册python环境变量:假设python的安装路径为c:\p ...
- jsonp的简单例子
jsonp的简单例子 index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...
- 黄聪:C#图片处理封装类(裁剪、缩放、清晰度、加水印、生成缩略图)有示例(转)
C#图片处理示例(裁剪,缩放,清晰度,水印) 吴剑 2011-02-20 原创文章,转载必需注明出处:http://www.cnblogs.com/wu-jian/ 前言 需求源自项目中的一些应用,比 ...
- linux网络不同的解决办法
贯标防火墙,iptables 注释掉/etc/hosts的localhost的ipv6地址映射