hdu4738Caocao's Bridges
什么?有人要炸我的桥?!D飞他(心疼周瑜大都督)
这个就是求割边/桥了。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std; int n,m;
struct node
{
int x,y,d,t,next;
}a[];int len,last[];
void ins(int x,int y,int d,int t)
{
len++;
a[len].x=x;a[len].y=y;a[len].d=d;a[len].t=t;
a[len].next=last[x];last[x]=len;
} int z,dfn[],low[];
int top,sta[];
int bp,bridge[];
void tarjan(int x,int pre)
{
dfn[x]=low[x]=++z;
sta[++top]=x;
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(dfn[y]==)
{
tarjan(y,k);
low[x]=min(low[x],low[y]);
}
else if(a[pre].t!=a[k].t)
low[x]=min(low[x],dfn[y]);
}
if(dfn[x]==low[x])
{
if(pre!=)
bridge[++bp]=pre;
int i;
do{
i=sta[top];top--;
}while(i!=x);
}
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==)break; int x,y,d;
len=;memset(last,,sizeof(last));
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&d);
ins(x,y,d,i);ins(y,x,d,i);
} z=top=bp=;
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
tarjan(,); bool bk=true;
for(int i=;i<=n;i++)
if(dfn[i]==){bk=false;break;}
if(bk==false){printf("0\n");continue;} int ans=(<<);
for(int i=;i<=bp;i++)
ans=min(ans,a[bridge[i]].d);
printf("%d\n",(ans==(<<))?-:((ans==)?:ans));
}
return ;
}
hdu4738Caocao's Bridges的更多相关文章
- hdu 4738 Caocao's Bridges 图--桥的判断模板
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- POJ2288 Islands and Bridges
Description Given a map of islands and bridges that connect these islands, a Hamilton path, as we al ...
- 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: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- ZOJ 2588 Burning Bridges(求含重边的无向连通图的割边) - from lanshui_Yang
Burning Bridges Time Limit: 5 Seconds Memory Limit: 32768 KB Ferry Kingdom is a nice little country ...
- zoj 2588 Burning Bridges【双连通分量求桥输出桥的编号】
Burning Bridges Time Limit: 5 Seconds Memory Limit: 32768 KB Ferry Kingdom is a nice little cou ...
- hdoj 4738 Caocao's Bridges【双连通分量求桥】
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- bzoj 2095: [Poi2010]Bridges [混合图欧拉回路]
2095: [Poi2010]Bridges 二分答案,混合图欧拉路判定 一开始想了一个上下界网络流模型,然后发现不用上下界网络流也可以 对于无向边,强制从\(u \rightarrow v\),计算 ...
- Luogu4655 [CEOI2017]Building Bridges
Luogu4655 [CEOI2017]Building Bridges 有 \(n\) 根柱子依次排列,每根柱子都有一个高度.第 \(i\) 根柱子的高度为 \(h_i\) . 现在想要建造若干座桥 ...
随机推荐
- Android 获取android安装apk框的安装状态(如点击取消、返回)
最近鼓捣android,碰到个问题,因为没有root权限,需要调用Intent安装apk,但需要获取用户是否安装了(如,用户点击了返回或取消),查了很多文章,最后可以解决,但有瑕疵,解决方法如下: p ...
- 把多种验证规则用到一个model上
基于标记特性的Model验证,真的太棒了,与jquery validate结合后激情四射,有木有,一句话完成前后端验证.简直让人秒爱... 但是爱是爱了,生活中总会有些小摩擦,这不问题来了:看图中那个 ...
- js 学习笔记---基本概念
早已接触javascript多年之后,竟然还有这些概念混淆不清,毫不知情,说出来真实无地自容 ! 1.使用严格模式,"use strict",虽然不适用,但是要知道,以免别人使用时 ...
- 【转载】HTTP 请求头与请求体
原文地址: https://segmentfault.com/a/1190000006689767 HTTP Request HTTP 的请求报文分为三个部分 请求行.请求头和请求体,格式如图:一个典 ...
- Ubuntu 关闭guest用户
Ubuntu 关闭guest用户 ca0gu0@ub:~$ cat /etc/lightdm/lightdm.conf [SeatDefaults]autologin-user=falseallow- ...
- STL_string用法总结
参考自:http://blog.csdn.net/y990041769/article/details/8763366 1:string对象的定义和初始化以及读写 string s1; 默认 ...
- C# 返回值为 list<T>
public List<T> test<T>(List<T> EntityList) where T : class { return EntityList; }
- win10系统安装postgresql后无法连接
win10系统安装postgresql后在系统服务列表中找不到,连接不上数据库. 可以尝试关闭系统防火墙后重启电脑或者重装程序.
- 批量obj格式直接转gltf
在cesium中的模型需要的是gltf或glb格式的文件,之前的做法是用将模型从3d max中导出dae格式的文件(需要插件),然后用collada2gltf工具将dae格式转成gltf. 最近翻看c ...
- sysbench使用指南
sysbench 安装.使用和测试 摘要: sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据库的性能测试.目前支持的数据库有MySQ ...