题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=737

求桥的数量,也就是割边的数量。输入有点小坑,左右括号外必须得有个空格才行,起初以为是转义的问题。

 /*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; #define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%lld", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a))
#define lp p << 1
#define rp p << 1 | 1
#define pi 3.14159265359
#define RT return
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ;
typedef struct Bridge {
int u, v;
Bridge() {}
Bridge(int uu, int vv) : u(uu), v(vv) { if(u > v) swap(u, v); }
}Bridge; int n;
int dfn[maxn], low[maxn];
vi G[maxn];
vector<Bridge> b; void dfs(int u, int d, int p) {
low[u] = dfn[u] = d;
Rep(i, G[u].size()) {
int v = G[u][i];
if(!dfn[v]) {
dfs(v, d+, u);
low[u] = min(low[u], low[v]);
if(low[v] > dfn[u]) b.push_back(Bridge(u, v));
}
else if(p != v) low[u] = min(low[u], dfn[v]);
}
} bool cmp(Bridge x, Bridge y) {
if(x.u == y.u) return x.v < y.v;
return x.u < y.u;
} int main() {
// FRead();
int u, v, p;
while(~Rint(n)) {
if(n == ) {
printf("0 critical links\n\n");
continue;
}
Cls(dfn); Cls(low); b.cl();
Rep(i, n+) G[i].cl();
Rep(i, n) {
Rint(u);
scanf(" (%d) ", &p);
W(p) {
Rint(v);
G[u].push_back(v);
G[v].push_back(u);
}
}
Rep(i, n) if(!dfn[i]) dfs(i, , i);
sort(b.begin(), b.end(), cmp);
printf("%d critical links\n", b.size());
Rep(i, b.size()) {
printf("%d - %d\n", b[i].u, b[i].v);
}
printf("\n");
}
RT ;
}

[UVA796]Critical Links(割边, 桥)的更多相关文章

  1. UVA796 Critical Links —— 割边(桥)

    题目链接:https://vjudge.net/problem/UVA-796 In a computer network a link L, which interconnects two serv ...

  2. uva-796.critical links(连通图的桥)

    本题大意:求出一个无向图的桥的个数并且按照顺序输出所有桥. 本题思路:注意判重就行了,就是一个桥的裸题. 判重思路目前知道的有两种,第一种是哈希判重,第二种和邻接矩阵的优化一样,就是只存图的上半角或者 ...

  3. UVA796 Critical Links(求桥) 题解

    题意:求桥 思路:求桥的条件是:(u,v)是父子边时 low[v]>dfn[u] 所以我们要解决的问题是怎么判断u,v是父子边(也叫树枝边).我们在进行dfs的时候,要加入一个fa表示当前进行搜 ...

  4. UVA796 - Critical Links(Tarjan求桥)

    In a computer network a link L, which interconnects two servers, is considered critical if there are ...

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

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

  6. Uva 796 Critical Links 找桥

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

  7. Uva796 Critical Links

    用tarjan缩点 然后用dfn[u] < low[v]缩点并且保存起来 在sort一遍输出 #include<stdio.h> #include<string.h> # ...

  8. UVA796:Critical Links(输出桥)

    Critical Links 题目链接:https://vjudge.net/problem/UVA-796 Description: In a computer network a link L, ...

  9. Light OJ 1026 - Critical Links (图论-双向图tarjan求割边,桥)

    题目大意:双向联通图, 现在求减少任意一边使图的联通性改变,按照起点从小到大列出所有这样的边 解题思路:双向边模版题 tarjan算法 代码如下: #include<bits/stdc++.h& ...

随机推荐

  1. fawef

    欢迎使用马克飞象 @(示例笔记本)[马克飞象|帮助|Markdown] 马克飞象是一款专为印象笔记(Evernote)打造的Markdown编辑器,通过精心的设计与技术实现,配合印象笔记强大的存储和同 ...

  2. busying

    罪过 ,最近好忙  ,好久没有发表东西了, 连英语单词都写错了

  3. tomcat配置及使用 环境变量设置

    Tomcat的配置及测试: 第一步:下载tomcat,然后解压到任意盘符 第二步:配置系统环境变量 我这里是tomcat5.5,解压到的D盘 (路径为: D:\Program Files\tomcat ...

  4. windows android studio 编译Jni动态库

    项目需要,折腾了半天搞定windows android studio环境编译Jni动态库,现记录下来. 准备安装环境: 1. android studio 下载地址是http://www.androi ...

  5. BZOJ1692: [Usaco2007 Dec]队列变换

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 594  Solved: 246[Submit][Sta ...

  6. 2014 Multi-University Training Contest 8

    官方解题报告:http://blog.sina.com.cn/s/blog_a19ad7a10102uzj7.html Area of Mushroom http://acm.hdu.edu.cn/s ...

  7. getHibernateTemplate()为NUll

    getHibernateTemplate()为NUll,困扰好几天了,网上也找了好些方法一直解决不掉15 小弟刚刚开始学SSH,是用的Struts2+Hibernate+Spring,运行的时候发现g ...

  8. Unity3D 相关项目代码

    一.Application.PresistentDataPath 注意最后面是没有/的 public static string PresistentDataPathForEditor = " ...

  9. linux源代码阅读笔记 fork和execve的区别

    1. man exec就可以知到: The exec() family of functions replaces the current process image with a new proce ...

  10. hdu 4315 Climbing the Hill 博弈论

    题意:有n个人爬山,山顶坐标为0,其他人按升序给出,不同的坐标只能容纳一个人(山顶不限),Alice和Bob轮流选择一个人让他移动任意步,但不能越过前面的人,且不能和前面一个人在相同的位置.现在有一个 ...