输出桥。

#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. portal安装常见问题

    1.创建portaladmin的url? https://portal.smart.ningbo:7443/arcgis/home/createadmin.html 2.创建portaladmin一闪 ...

  2. timeit模块 与 time模块,计时的区别

    time  模块,理解容易 import time time_start = time.time() time_end = time.time() time_use = time_end - time ...

  3. sql server 查询表基本信息sql

    SELECT c.name,t.name TYPE,c.max_length,c.precision,c.scale,p.value FROM sys.systypes t INNER JOIN sy ...

  4. php curl拉取远程图片

    <?php $url = "图片绝对地址/thumbnail.jpg"; $filename = 'curl.jpg'; getImg($url, $filename); / ...

  5. hdu5514 非2的次幂容斥原理

    /* 1 126 223092870 210 330 390 462 510 546 570 690 714 770 798 858 910 966 1122 1155 1190 1254 1326 ...

  6. sublime text 安装 SFTP

    1  先安装Package Control import urllib.request,os,hashlib; h = 'df21e130d211cfc94d9b0905775a7c0f' + '1e ...

  7. Unity3D研究院之在把代码混淆过的游戏返混淆回来(七十七)

    最近一直在找如何在MAC上混淆Android的DLL,至今没能找到合适的,有大神知道记得告诉我喔.今天群里有人说了一个混淆代码和返混淆代码的工具de4dot ,不查不知道一查吓一跳.这玩意可以把别人混 ...

  8. ping 计算机全名,返回的不是IP地址

    今天想看一下机子的IP地址,结果关闭局域防火墙后,在命令行中使用ping 计算机全名,返回的不是IP地址 其实,这也是一种IP地址,IP6地址 原因:默认情况下,win7以上的操作系统,ping 计算 ...

  9. android app 集成 支付宝支付 微信支付

    项目中部分功能点需要用到支付功能,移动端主要集成支付宝支付和微信支付 支付宝sdk以及demo下载地址:https://doc.open.alipay.com/doc2/detail.htm?spm= ...

  10. 【第三篇】Volley图片加载之NetworkImageView代码分析

    在Volley的使用之加载图片讲过使用NetWorkImageView进行图片加载的例子,本文着重讲解NetWorkImageView内部是如何实现的,以及Volley这个控件有什么特性.   1,通 ...