POJ - 3177 Redundant Paths 说说连通分量吧
----我想说说双联通分量还有割点和桥
1.割点(一个点,如果没有这一个点,图就会变得不连通)
2.桥(一条边,断开这条边就会让图不连通)
3.点双连通(没割点的图)
4.边双连通(没桥的图)
5.割点之间不一定有桥!!!
6.桥两端不一定是割点!!!
对了,关于tarjan我还想再说说
就像下图,圈住的是点双连通分量和边双连通分量

本题要把有桥图,变成边双连通图,问你要加几条边
下图说了具体做法

这就是我找到的关于双联通分量的见解了
代码奉上
#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<algorithm>
#define maxn 5010
#define INF 10000
using namespace std; int low[maxn], dfn[maxn], clor[maxn], df, clr;
vector<int>G[maxn];
void insert(int be, int en) {
G[be].push_back(en);
}
int n, m;
stack<int>s;
int de[maxn];
void tarjan(int x,int fa) {
low[x] = dfn[x] = ++df;
s.push(x); for (int i = 0; i < G[x].size(); i++) {
int p = G[x][i];
if (p == fa) continue;
if (!dfn[p]) {
tarjan(p, x);
low[x] = min(low[x], low[p]);
}
else {
low[x] = min(low[x], dfn[p]);
}
}
if (low[x] == dfn[x]) {
clr++;
while (1) {
int a = s.top();
s.pop();
clor[a] = clr;
if (a == x) break;
}
}
}
map<long long, int>ins;
int main() {
int be, en;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d %d", &be, &en);
long long an = be * INF + en;
long long cc = en * INF + be;
if (ins[an] == 0 || ins[cc] == 0) {
insert(be, en);
insert(en, be);
ins[cc] = 1;
ins[an] = 1;
} }
for (int i = 1; i <= n; i++) {
if (!dfn[i]) tarjan(i, -1);
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < G[i].size(); j++) {
int p = G[i][j];
if (clor[i] != clor[p]) {
de[clor[i]]++;
de[clor[p]]++;
}
}
}
int cnt = 0;
for (int i = 1; i <= clr; i++) {
if (de[i] == 2) cnt++;//因为一个边有两个端点,每个边都被算计了两次!
}
printf("%d\n", (cnt + 1) / 2);
return 0;
}
POJ - 3177 Redundant Paths 说说连通分量吧的更多相关文章
- tarjan算法求桥双连通分量 POJ 3177 Redundant Paths
POJ 3177 Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12598 Accept ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
- [双连通分量] POJ 3177 Redundant Paths
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13712 Accepted: 5821 ...
- POJ 3177 Redundant Paths(边双连通的构造)
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13717 Accepted: 5824 ...
- POJ 3177——Redundant Paths——————【加边形成边双连通图】
Redundant Paths Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- poj 3177 Redundant Paths
题目链接:http://poj.org/problem?id=3177 边双连通问题,与点双连通还是有区别的!!! 题意是给你一个图(本来是连通的),问你需要加多少边,使任意两点间,都有两条边不重复的 ...
- poj 3177 Redundant Paths【求最少添加多少条边可以使图变成双连通图】【缩点后求入度为1的点个数】
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11047 Accepted: 4725 ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction
这两题是一样的,代码完全一样. 就是给了一个连通图,问加多少条边可以变成边双连通. 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话,把双连通子图收缩为一个点,形成一颗树 ...
- POJ - 3177 Redundant Paths(边双连通分支)(模板)
1.给定一个连通的无向图G,至少要添加几条边,才能使其变为双连通图. 2. 3. //边双连通分支 /* 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话, 把双连通子图 ...
随机推荐
- 动态设置iframe高度
<%//动态设置iframe高度 %><script language="javascript" type="text/javascript" ...
- Python两个字典键同值相加的几种方法
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/Jerry_1126/article/de ...
- 基于 springMVC 的 RESTful HTTP API 实践(服务端)
理解 REST REST(Representational State Transfer),中文翻译叫"表述性状态转移".是 Roy Thomas Fielding 在他2000年 ...
- 2018-8-10-添加右键使用-SublimeText-打开
title author date CreateTime categories 添加右键使用 SublimeText 打开 lindexi 2018-08-10 19:16:52 +0800 2018 ...
- "不用谢" 的11种表达
说Thank you ,机械版的反应you are welcome.虽然没错,但实在太老掉牙,在国外使用率不高: 随性,不足挂齿的小事 Not a problem 别放在心上 Any time 有事随 ...
- Python错误:AttributeError: 'generator' object has no attribute 'next'解决办法
今天在学习生成器对象(generation object)运行以下代码时,遇到了一个错误: #定义生成器函数def liebiao(): for x in range(10): yield x#函数调 ...
- Sublime插件:增强篇
Sublime Text 如何安装插件详见:https://packagecontrol.io/installation WordCount:可以实时显示当前文件的字数. 安装后,后下角多出字数 En ...
- 解析P2P金融的业务安全
看了很多乙方同学们写的业务安全,总结下来,其出发点主要是在技术层面风险问题.另外捎带一些业务风险.今天我要谈的是甲方眼里的业务安全问题,甲方和乙方在业务安全的视野上会有一些区别和一些重合.在同一个问题 ...
- JavaScript中判断整数的方法
一.使用取余运算符判断 任何整数都会被1整除,即余数是0.利用这个规则来判断是否是整数. 1 2 3 4 5 function isInteger(obj) { return obj%1 == ...
- 原生js设置audio在谷歌浏览器自动播放
https://www.cnblogs.com/sandraryan/ 谷歌浏览器更新后禁止了autoplay功能,但是有时候可能会需要自动播放. 研究了一段代码. <!DOCTYPE html ...