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. //边双连通分支 /* 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话, 把双连通子图 ...
随机推荐
- Vue组件跨层级通信
正常组件间通信 父->子组件 是通过属性传递 子->父组件 是通过this.$emit()传递 this.$emit()返回的是this,如果需要一些值 可使用callback方式传递 p ...
- c++第四次作业:继承
继承与派生 基本概念和语法 概念 继承与派生是同一过程从不同角度看 保持已有的特性而构造新类的过程称为继承. 在已有类的基础上新增自己的特性而产生新类的过程为派生. 被继承的已有类称为基类(父类) 派 ...
- shell 解析json
未完待续 ### 解析api json文件为csv文件 cd /api ` do id=$(echo ${i}|sed 's/.html//') echo -n "${id}|" ...
- APICloud原生APP中ajax需要用api.ajax
报错截屏: APICloud原生APP中ajax请求需要用api.ajax(api对象的ajax方法来替代),否则会将引起请求失败. APICloud api.ajax
- day3_python之函数参数
一.形参 在定义函数时,括号内的参数称为形参,特点:形参就是变量名 def foo(x, y): # x=1,y=2 print(x) print(y) 二.实参 在调用函数时,括号内的参数成为实参, ...
- Android教程-01 Android Studio创建第一个项目
视频教程建议采用超清模式, 关注更多视频订阅我的优酷 最近一直使用Android Studio 简单把Android Studio介绍下 1. 首先介绍下 Android Studio的快捷键 由于之 ...
- 神经网络入门——6and感知机
AND 感知器练习 AND 感知器的权重和偏置项是什么? 把权重(weight1, weight2)和偏置项 bias 设置成正确的值,使得 AND 可以实现上图中的运算. 在这个例子 ...
- hdu 2069 Coin Change(完全背包)
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 最小生成树prim、
过年那几天确实没好好学习.在老家闲着也是闲着.可是就是没看书. 回来这几天又一直在弄个人博客.买域名云服务器备案什么的- -. 麻烦死了呢. 在腾讯花1块钱备案了一个网站www.goodgoodstu ...
- Native memory allocation (mmap) failed to map xxx bytes for committing reserved memory
遇到问题 在服务器上运行 nexus 出现Native memory allocation (mmap) failed to map 838860800 bytes for committing re ...