[UVA796]Critical Links(割边, 桥)
题目链接: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(割边, 桥)的更多相关文章
- UVA796 Critical Links —— 割边(桥)
题目链接:https://vjudge.net/problem/UVA-796 In a computer network a link L, which interconnects two serv ...
- uva-796.critical links(连通图的桥)
本题大意:求出一个无向图的桥的个数并且按照顺序输出所有桥. 本题思路:注意判重就行了,就是一个桥的裸题. 判重思路目前知道的有两种,第一种是哈希判重,第二种和邻接矩阵的优化一样,就是只存图的上半角或者 ...
- UVA796 Critical Links(求桥) 题解
题意:求桥 思路:求桥的条件是:(u,v)是父子边时 low[v]>dfn[u] 所以我们要解决的问题是怎么判断u,v是父子边(也叫树枝边).我们在进行dfs的时候,要加入一个fa表示当前进行搜 ...
- UVA796 - Critical Links(Tarjan求桥)
In a computer network a link L, which interconnects two servers, is considered critical if there are ...
- Uva 796 Critical Links (割边+排序)
题目链接: Uva 796 Critical Links 题目描述: 题目中给出一个有可能不连通的无向图,求出这个图的桥,并且把桥按照起点升序输出(还有啊,还有啊,每个桥的起点要比终点靠前啊),这个题 ...
- Uva 796 Critical Links 找桥
这个题很简单,但是输入有毒,用字符串的我一直RE 然后换成这样瞬间AC #include <stdio.h> #include <string.h> #include < ...
- Uva796 Critical Links
用tarjan缩点 然后用dfn[u] < low[v]缩点并且保存起来 在sort一遍输出 #include<stdio.h> #include<string.h> # ...
- UVA796:Critical Links(输出桥)
Critical Links 题目链接:https://vjudge.net/problem/UVA-796 Description: In a computer network a link L, ...
- Light OJ 1026 - Critical Links (图论-双向图tarjan求割边,桥)
题目大意:双向联通图, 现在求减少任意一边使图的联通性改变,按照起点从小到大列出所有这样的边 解题思路:双向边模版题 tarjan算法 代码如下: #include<bits/stdc++.h& ...
随机推荐
- [转]教大家如何打造使用Tcpview(tcp查看器
原文地址:教大家如何打造使用Tcpview(tcp查看器)作者:jybasenet3 一玩 VS 对战平台的同学有一次发现了一个可以踢人的方法,就是用 TcpView 把那个连 接关掉.后来VS ...
- rJava配置
1. 下载安装R-3.1.1-win.exe: 2. 在R中安装rJava > install.packages("rJava") 3. 设置环境变量: PATH:D:\So ...
- Netty4.x中文教程系列(四) 对象传输
Netty4.x中文教程系列(四) 对象传输 我们在使用netty的过程中肯定会遇到传输对象的情况,Netty4通过ObjectEncoder和ObjectDecoder来支持. 首先我们定义一个U ...
- maven+springMVC+mybatis+junit详细搭建过程 ***
springMVC+mybatis框架搭建 在上一遍博客中以及讲诉了新建maven项目的流程,现在紧跟上一遍文章,接着搭建spring项目 首先我们先要弄清搭建项目的一般流程,需要注意哪些方面,想要什 ...
- [设计模式] 10 外观模式 facade
外观模式应该是用的很多的一种模式,特别是当一个系统很复杂时,系统提供给客户的是一个简单的对外接口,而把里面复杂的结构都封装了起来.客户只需使用这些简单接口就能使用这个系统,而不需要关注内部复杂的结构. ...
- MonoBehaviour.StopCoroutine
MonoBehaviour.StopCoroutine Description Stops all coroutines named methodName running on this behavi ...
- Unity3d集成移动MM SDK 2.2的技术要点(坑爹的MM SDK)
原地址:http://dong2008hong.blog.163.com/blog/static/4696882720140423517951/ U3D集成移动MM的SDK绝对是以坑爹为主的东西. 浪 ...
- Firefox下网页缩放时防止div被挤到下一层
http://wu110cheng.blog.163.com/blog/static/13334965420121120102439190/ Firefox下网页缩放时防止div被挤到下一层 问题:三 ...
- 如何用 ANTLR 4 实现自己的脚本语言?
ANTLR 是一个 Java 实现的词法/语法分析生成程序,目前最新版本为 4.5.2,支持 Java,C#,JavaScript 等语言,这里我们用 ANTLR 4.5.2 来实现一个自己的脚本语言 ...
- POJ 2155 Matrix (二维线段树入门,成段更新,单点查询 / 二维树状数组,区间更新,单点查询)
题意: 有一个n*n的矩阵,初始化全部为0.有2中操作: 1.给一个子矩阵,将这个子矩阵里面所有的0变成1,1变成0:2.询问某点的值 方法一:二维线段树 参考链接: http://blog.csdn ...