输出桥。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std; const int maxn = + ;
const int Maxn = * + ;
int low[maxn];
int dfn[maxn];
int U[maxn], V[maxn]; struct Edge
{
int from, to, id, ans;
} edge[Maxn];
vector<int>G[maxn];
int N, M;
int tmpdfn;
int tot;
int Start, End; struct ANSS
{
int first, second;
}ANS[Maxn]; void init()
{
for (int i = ; i<maxn; i++) G[i].clear();
memset(low, , sizeof(low));
memset(dfn, , sizeof(dfn));
low[] = dfn[] = ;
tmpdfn = ;
tot = ;
} void AddEdge(int u, int v)
{
edge[tot].from = u;
edge[tot].to = v;
edge[tot].id = tot;
edge[tot].ans = ;
G[u].push_back(tot);
tot++; edge[tot].from = v;
edge[tot].to = u;
edge[tot].id = tot;
edge[tot].ans = ;
G[v].push_back(tot);
tot++; } int Tarjan(int u, int id)
{
tmpdfn++;
int lowu = dfn[u] = tmpdfn;
for (int i = ; i<G[u].size(); i++)
{
int B = G[u][i];
if (!dfn[edge[B].to])
{
int lowv = Tarjan(edge[B].to, edge[B].id);
lowu = min(lowu, lowv);
if (lowv >= dfn[u])
{
if (lowv>dfn[u])
edge[B].ans = ;
}
}
else if (dfn[edge[B].to])
{
if (edge[B].id / == id / ) continue;
lowu = min(lowu, dfn[edge[B].to]);
}
} low[u] = lowu;
return lowu;
} bool cmp(const ANSS&a, const ANSS&b)
{
if (a.first == b.first) return a.second < b.second;
return a.first < b.first;
} void Display_Cutting_edge()
{
int AA = ;
for (int i = ; i < * M; i++)
{
if (edge[i].ans)
{
if (edge[i].from < edge[i].to)
{
ANS[AA].first = edge[i].from;
ANS[AA].second = edge[i].to;
}
else
{
ANS[AA].first = edge[i].to;
ANS[AA].second = edge[i].from;
}
AA++;
}
}
printf("%d critical links\n", AA);
sort(ANS, ANS + AA, cmp);
for (int i = ; i < AA; i++)
printf("%d - %d\n", ANS[i].first-, ANS[i].second-);
printf("\n");
} int main()
{
while (~scanf("%d", &N))
{
init();
M = ;
for (int i = ; i <= N; i++)
{
int from,TTT;
scanf("%d (%d)", &from, &TTT);
while (TTT--)
{
int too;
scanf("%d", &too);
if (from >= too) continue;
U[M] = from + ; V[M] = too + ;
AddEdge(U[M], V[M]);
M++;
}
}
Start = ; End = N;
Tarjan(, -);
for (int i = ; i <= N; i++) if (!dfn[i]) Tarjan(i, -);
Display_Cutting_edge();
}
return ;
}

UVA 796 Critical Links的更多相关文章

  1. Uva 796 Critical Links (割边+排序)

    题目链接: Uva 796 Critical Links 题目描述: 题目中给出一个有可能不连通的无向图,求出这个图的桥,并且把桥按照起点升序输出(还有啊,还有啊,每个桥的起点要比终点靠前啊),这个题 ...

  2. uva 796 Critical Links(无向图求桥)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. UVA 796 Critical Links(Tarjan求桥)

    题目是PDF就没截图了 这题似乎没有重边,若有重边的话这两点任意一条边都不是桥,跟求割点类似的原理 代码: #include <stdio.h> #include <bits/std ...

  4. UVA 796 - Critical Links (求桥)

    Critical Links  In a computer network a link L, which interconnects two servers, is considered criti ...

  5. Uva 796 Critical Links 找桥

    这个题很简单,但是输入有毒,用字符串的我一直RE 然后换成这样瞬间AC #include <stdio.h> #include <string.h> #include < ...

  6. UVA 796 Critical Links(无向图求桥)

    题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号  (与这个点相连的点的个数m)  依次是m个点的   输入到文件结束. 桥输出的时候需要排序   知识汇总: 桥:   无向连通 ...

  7. UVA 796 Critical Links (tarjan算法求割边)

    这是在kuangbin的题目里看到的,不得不吐槽一下,题目中居然没给出数据范围,还是我自己猜的-本来是一道挺裸的题,但是我wa了好多次,原因就是这里面有两个坑点,1重边特判,2输出时左边必须比右边小. ...

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

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

  9. UVA 796 Critical Links —— (求割边(桥))

    和求割点类似,只要把>=改成>即可.这里想解释一下的是,无向图没有重边,怎么可以使得low[v]=dfn[u]呢?只要它们之间再来一个点即可. 总感觉图论要很仔细地想啊- -一不小心就弄混 ...

随机推荐

  1. Docker 总结

    版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[+] Docker总结 简单介绍 1 Docker 架构 安装和环境配置 1 mac 11 brew安装 11 dmg文件安装 1 ...

  2. CentOS7 citus9.5 集群安装及管理

    1 所有节点配置 #------服务安装 服务yum update -y #------扩展依赖安装yum install -y epel-release && yum update ...

  3. javaMail邮件发送的简单实现

    package com.test.mail; import java.util.Properties; import javax.mail.Message; import javax.mail.Ses ...

  4. HDU 4451 Dressing

    HDU 4451 Dressing 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4451 Description Wangpeng has ...

  5. Node.js API

    Node.js v4.4.7 Documentation(官方文档) Buffer Prior to the introduction of TypedArray in ECMAScript 2015 ...

  6. Android:Asmack能登录但是获取不到联系人的问题

    先说一下:换了N个jar包,换了N个OpenFire,就是获取不到联系人.但是能登录.特别纳闷,百度不到,google一下,有人隐约说了下权限的问题. 终于搞出来了,总结一下,浪费了一整天的时间.(码 ...

  7. 《JavaScript高级程序设计》读书笔记 ---Function 类型

    说起来ECMAScript 中什么最有意思,我想那莫过于函数了——而有意思的根源,则在于函数实际上是对象.每个函数都是Function 类型的实例,而且都与其他引用类型一样具有属性和方法.由于函数是对 ...

  8. intellij idea 12 搭建maven web项目 freemarker + spring mvc

    配置spring mvc ,写这篇文章的时候spring已经出了4.0 这里还是用稳定的3.2.7.RELEASE,先把spring和freemarker配置好 1.spring mvc配置 在web ...

  9. Linux系统VPS/服务器安装WINDOWS桌面环境可以采用的几个方法

    我们公司的几个项目需要在WINDOWS桌面类型的界面操作,哪怕仅有一个浏览器远程操作也是可以的,我们运维部门得到的任务就是需要能在已有的Linux系统的VPS.服务器环境中能够远程操作,至少需要能可以 ...

  10. js数组、对象、正则

    1.根据给定的条件在原有的数组上,得到所需要的新数组var a = [-1, -1, 1, 2, -2, -2, -3, -3, 3, -3];function f(s, e) {    var re ...