(连通图 模板题 无向图求桥)Critical Links -- UVA -- 796
链接:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82833#problem/C
说实话还不是太懂,自己再写点题理解理解!
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define N 1005 struct Edge{int v, next;}e[N*N];
struct Bridge{int u, v;}bri[N]; int bnt, n;
int Head[N], cnt;
int dfn[N], low[N], f[N], Index; bool cmp(Bridge a, Bridge b)
{
if(a.u != b.u)
return a.u < b.u;
return a.v < b.v;
} void Init()
{
cnt = bnt = Index = ;
memset(low, , sizeof(low));
memset(dfn, , sizeof(dfn));
memset(f, , sizeof(f)); for(int i=; i<=n; i++)
{
Head[i] = -;
dfn[i] = ;
}
} void AddEdge(int u, int v)
{
e[cnt].v = v;
e[cnt].next = Head[u];
Head[u] = cnt++;
} void TarJan(int u, int fa)
{
f[u] = fa;
low[u] = dfn[u] = ++Index; for(int j=Head[u]; j!=-; j=e[j].next)
{
int v = e[j].v; if(!dfn[v])
{
TarJan(v, u);
low[u] = min(low[u], low[v]);
}
else if(v!=fa)
low[u] = min(low[u], dfn[v]);
}
} int main()
{
while(scanf("%d", &n)!=EOF)
{
int i, j, u, v, m; Init(); for(i=; i<n; i++)
{
scanf("%d (%d)", &u, &m); for(j=; j<m; j++)
{
scanf("%d", &v);
AddEdge(u, v);
}
} for(i=; i<n; i++)
{
if(!dfn[i])
TarJan(i, i);
} for(i=; i<n; i++)
{
int u = f[i];
if(low[i] > dfn[u])
{
bri[bnt].u = min(u, i);
bri[bnt++].v = max(u, i);
}
} sort(bri, bri+bnt, cmp); printf("%d critical links\n", bnt); for(i=; i<bnt; i++)
printf("%d - %d\n", bri[i].u, bri[i].v);
printf("\n");
}
return ;
}
(连通图 模板题 无向图求桥)Critical Links -- UVA -- 796的更多相关文章
- (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- C - Critical Links - uva 796(求桥)
题意:有一些网络通过一些线路连接,求关键的连接,也就是桥,如果删除这个链接那么会产生两个子树 分析:注意一下图不是连通图即可 ************************************* ...
- kuangbin专题 专题九 连通图 Critical Links UVA - 796
题目链接:https://vjudge.net/problem/UVA-796 题目:裸的求桥,按第一个元素升序输出即可. #include <iostream> #include < ...
- [kuangbin带你飞]专题九 连通图C - Critical Links UVA - 796
这道题就是要求桥的个数. 那么桥相应的也有判定的定理: 在和u相邻的节点中,存在一个节点是最小的时间戳都比 当前u的访问次序要大,也就是说这个点是只能通过果u到达,那么 他们之间相邻的边就是的桥 #i ...
- UVA 796 Critical Links(模板题)(无向图求桥)
<题目链接> 题目大意: 无向连通图求桥,并将桥按顺序输出. 解题分析: 无向图求桥的模板题,下面用了kuangbin的模板. #include <cstdio> #inclu ...
- UVA 796 Critical Links(无向图求桥)
题目大意:给你一个网络要求这里面的桥. 输入数据: n 个点 点的编号 (与这个点相连的点的个数m) 依次是m个点的 输入到文件结束. 桥输出的时候需要排序 知识汇总: 桥: 无向连通 ...
- 【并查集缩点+tarjan无向图求桥】Where are you @牛客练习赛32 D
目录 [并查集缩点+tarjan无向图求桥]Where are you @牛客练习赛32 D PROBLEM SOLUTION CODE [并查集缩点+tarjan无向图求桥]Where are yo ...
- HDU 4738--Caocao's Bridges(重边无向图求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- uva 796 Critical Links(无向图求桥)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- eclipse 自动生成json格式的toString()方法
文本代码 {"${member.name()}":"${member.value}", "${otherMembers}"}
- 【346】TF-IDF
Ref: 文本挖掘预处理之向量化与Hash Trick Ref: 文本挖掘预处理之TF-IDF Ref: sklearn.feature_extraction.text.CountVectorizer ...
- 显示AVI文件的桢数
procedure TForm1.Button1Click(Sender: TObject);begin MediaPlayer1.TimeFormat := tfFrames; ShowMess ...
- 显示AVI的第一桢
procedure TForm1.Button1Click(Sender: TObject);begin Application.ProcessMessages; MediaPlayer1.Ope ...
- Delphi 动态数组合并
TIntArray = array of Integer; function MergeArray(const ArrayA, ArrayB: TIntArray): TIntArray; var i ...
- java script sleep synchronous
function sleep(milliseconds) { var start = new Date().getTime(); for (var i = 0; i < 1e7; i++) { ...
- php 过滤emoji
function filter_emoji_string($str){ $str = trim($str); $str = preg_replace_callback('/./u',function ...
- django MongoDB上传文件
django上传文件,查询到的资料都是用的django自己的models.Model类,去定义一个FileField类型的存储文件,并且在里面加一句upload_to,如下所示: 但是如果用mon ...
- 53. Maximum Subarray (Array; DP)
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- 【校招面试 之 C/C++】第11题 C++ 纯虚函数
1.纯虚函数 成员函数的形参后面写上=0,则成员函数为纯虚函数. 纯虚函数声明: virtual 函数类型 函数名 (参数表列) = 0: class Person { virtual void Di ...