oj问题,待修改,存档。

 #include<stdio.h>
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
#define maxn 111111
#define inf 11111111
stack<int>s;
int dfn[maxn],low[maxn];
int iscut[maxn];
int cnt,scc,ans,clc;
struct edge{
int to,next,w,id;
}e[maxn*];
int head[maxn];
void add(int u,int v,int w,int id){
e[cnt].to=v;e[cnt].next=head[u];e[cnt].w=w;e[cnt].id=id;
head[u]=cnt++;
}
void init(){
memset(dfn,,sizeof dfn);
memset(low,,sizeof low);
memset(head,-,sizeof head);
memset(iscut,,sizeof iscut);
cnt=;scc=,clc=;
}
void dfs(int u,int fa){
low[u]=dfn[u]=++clc;
for(int i=head[u];i!=-;i=e[i].next){
int v=e[i].to;
if(e[i].id==fa)continue;
if(!dfn[v]){
dfs(v,e[i].id);
low[u]=min(low[u],low[v]);
if(low[v]>dfn[u]){
ans=min(ans,e[i].w);
}
}
else low[u]=min(low[u],dfn[v]);
}
}
int n,m,a,b,c;
int main(){
while(~scanf("%d%d",&n,&m)){
if(!n&&!m)break;
init();
for(int i=;i<=m;++i){
scanf("%d%d%d",&a,&b,&c);
add(a,b,c,i);
add(b,a,c,i);
}
int blo=;ans=inf;
for(int i=;i<=n;++i)
if(!dfn[i]){
blo++;
dfs(i,-);
}
if(blo>)printf("0\n");
else if(!ans)printf("1\n");
else if(ans==inf)printf("-1\n");
else printf("%d\n",ans);
}
return ;
}

[hdu4738]求桥模板的更多相关文章

  1. poj3694(lca + tarjan求桥模板)

    题目链接: http://poj.org/problem?id=3694 题意: 给出一个 n 个节点 m 条边的图, 然后有 q 组形如 x, y 的询问, 在前面的基础上连接边 x, y, 输出当 ...

  2. UVA 796 Critical Links(模板题)(无向图求桥)

    <题目链接> 题目大意: 无向连通图求桥,并将桥按顺序输出. 解题分析: 无向图求桥的模板题,下面用了kuangbin的模板. #include <cstdio> #inclu ...

  3. Tarjan求强连通分量、求桥和割点模板

    Tarjan 求强连通分量模板.参考博客 #include<stdio.h> #include<stack> #include<algorithm> using n ...

  4. HDU4738:Caocao's Bridges(求桥)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. 求无向图的割点和桥模板(tarjan)

    一.基本概念 1.桥:若无向连通图的边割集中只有一条边,则称这条边为割边或者桥 (离散书上给出的定义.. 通俗的来说就是无向连通图中的某条边,删除后得到的新图联通分支至少为2(即不连通: 2.割点:若 ...

  6. tarjan求桥、割顶

    若low[v]>dfn[u],则(u,v)为割边.但是实际处理时我们并不这样判断,因为有的图上可能有重边,这样不好处理.我们记录每条边的标号(一条无向边拆成的两条有向边标号相同),记录每个点的父 ...

  7. 【HDU4612】 双连通分量求桥

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 题目大意:给你一个无向图,问你加一条边后最少还剩下多少多少割边. 解题思路:好水的一道模板题.先 ...

  8. tarjan算法求桥双连通分量 POJ 3177 Redundant Paths

    POJ 3177 Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12598   Accept ...

  9. Tarjan 求桥,割,强连通

    最近遇到了这种模板题,记录一下 tarjan求桥,求割 #include <bits/stdc++.h> using namespace std; #define MOD 99824435 ...

随机推荐

  1. 继承ViewGroup类

    Android中,布局都是直接或间接的继承自ViewGroup类,其中,ViewGroup的直接子类目前有: AbsoluteLayout, AdapterView<T extends Adap ...

  2. mybatis--foreach,choose 小结

    写博客个人不喜欢写那种长篇大论.富有文採与哲学的文章,搞开发的就喜欢直击重点,仅仅记录重要的信息就好了,以后查看的时候也很方便! mybatis 中 在if语句或when中 假设推断一个字段是否和1同 ...

  3. MySQL中使用INNER JOIN来实现Intersect并集操作

    MySQL中使用INNER JOIN来实现Intersect并集操作 一.业务背景 我们有张表设计例如以下: CREATE TABLE `user_defined_value` ( `RESOURCE ...

  4. HTML 学习笔记 JQueryUI(Interactions,Widgets)

    Draggable 允许使用鼠标移动元素(拖动) demo <html>    <head>        <meta charset="UTF-8" ...

  5. Data Structure Binary Tree: Check for Children Sum Property in a Binary Tree

    http://www.geeksforgeeks.org/check-for-children-sum-property-in-a-binary-tree/ #include <iostream ...

  6. react服务端渲染

    一.服务端渲染的好处 1.SEO, 让搜索引擎更容易读取页面内容: 2.首屏渲染速度更快(重点),无需等待JS文件下载执行过程: 3.更易于维护,服务端和客户端可以共享某些代码: 二.实现原理 服务端 ...

  7. C语言“快速排序”函数写法

    代码是:C语言中快速排的写法,要加入头文件   <stdlib.h> qsort(数组名, 长度, 数据类型大小,比较算子 ): #include <stdio.h> #inc ...

  8. CodeForces - 540D Bad Luck Island —— 求概率

    题目链接:https://vjudge.net/contest/226823#problem/D The Bad Luck Island is inhabited by three kinds of ...

  9. netstat参数记录

    可以使用man netstat查看TCP的各种状态信息描述  ESTABLISHED       socket已经建立连接  CLOSED            socket没有被使用,无连接  CL ...

  10. python的上下文管理器

    直接上代码: f = open('123.txt','w') try: f.write('hello world') except Exception: pass finally: f.close() ...