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. //边双连通分支 /* 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话, 把双连通子图 ...
随机推荐
- 关于编码的发展演变:ASCII、GB2312、GBK、gb18030、Unicode、UTF-8
[1]ASCII 每个字符占据1bytes(字节),第一次以规范标准发表是在1967年,最后一次修订是在1986年.用二进制表示的话最高位必须为0(扩展的ASCII不在考虑范围内),因此ASCII只能 ...
- 巨蟒python全栈开发-第11阶段 ansible_project5
今日大纲 1.命令展示前端页面实现(下面有个断点) 2.命令下发后端展示
- 《C语言深度解剖》学习笔记之内存管理
第5章 内存管理 1.野指针 定义指针变量的同时最好初始化为NULL,用完指针后也将变量的值设置为NULL.也就是说除了使用时,别的时间都把它设置为NULL 2.堆,栈和静态区 堆:由malloc系列 ...
- HDFS命令行界面
- 从开源小白到 Apache Member,我的成长之路
我们走过的每一步路,都会留下印记,越坚实,越清晰. 近日,Apache 软件基金会(ASF)官方 Blog 宣布全球新增 40 位 Apache Member,张乎兴有幸成为其中一位. 目前,全球共有 ...
- git学习一——Pro-Git
1.配置用户名,邮箱 git config --global user.name "Mike" git config --global user.email Mike@exampl ...
- UIImageView xib里面拉伸图片技巧
拉伸图片的时候代码里和xib里面的图片名字去掉@2x,但是原始图片文件得要xxx@2x.png The X and Y values seem to be the positions for the ...
- Spark-shell批量命令执行脚本
#!/bin/bash source /etc/profile exec $SPARK_HOME/bin/spark-shell --queue tv --name spark-sql-test -- ...
- oracle 用EXISTS替代IN
在许多基于基础表的查询中,为了满足一个条件,往往需要对另一个表进行联接.在这种情况下, 使用EXISTS(或NOT EXISTS)通常将提高查询的效率. 低效: SELECT * FROM EMP ( ...
- 【BestCoder Round #93 1004】MG loves set
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=6022 [题意] 让你求一个集合的子集数目; 这个子集有要求; 即: 它所有元素的平方的和小于它所有 ...