输出桥。

#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. 【linux-shell】rsync

    https://en.wikipedia.org/wiki/Rsync https://en.wikipedia.org/wiki/Andrew_Tridgell 安德鲁.锤子,发布了rsync的第一 ...

  2. rzsz的安装

    rz,sz是Linux/Unix同Windows进行ZModem文件传输的命令行工具优点:比ftp命令方便,而且服务器不用打开FTP服务. sz:将选定的文件发送(send)到本地机器rz:运行该命令 ...

  3. java命名

    Package 的命名 Package 的名字应该都是由一个小写单词组成. Class 的命名 Class 的名字必须由大写字母开头而其他字母都小写的单词组成 Class 变量的命名 变量的名字必须用 ...

  4. jQuery(5)——动画

    jQuery中的动画 [show()方法和hide()方法] 在HTML文档中,为一个元素调用hide()方法,会将该元素的display样式改为“none”,show()方法将元素的display样 ...

  5. iScroll屏幕滑动函数封装总结

    //iScroll.js屏幕滚动函数 function funScroll(a,b) { var d; function beforload() { d = new iScroll(a, { chec ...

  6. OpenVPN GUI: "No TAP-WIN32 adapters on this system"

    找到C:\Program Files\TAP-Windows\bin 管理员身份运行: deltapall.bat addtap.bat

  7. Python统计栏目页面数量

    主要为了装个B,统计栏目页面数量时候用的,多线程基本照抄 http://www.cnblogs.com/fnng/p/3670789.html 关于对SEO有什么用处...我觉得...仅对本人有用,P ...

  8. CodeForces 703C Chris and Road

    数学,递推. 不知道有没有更加神奇的做法,我是这样想的: 首先,如果多边形完全在$y$轴左侧,那么答案为$\frac{w}{u}$. 剩下的情况就要先判断是否能在车开过之前跑过去,如果跑不过去,要在车 ...

  9. POJ 2656 Unhappy Jinjin

    #include <stdio.h> int main() { ) { int i, n; ; scanf("%d", &n); ) break; ; i &l ...

  10. Matches Puzzle Game

    Matches Puzzle Game 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5456 数位DP 首先我把C-A=B改为A+B=C(我觉得会简单 ...