1、给定一个连通的无向图G,至少要添加几条边,才能使其变为双连通图。

2、

3、

//边双连通分支
/*
去掉桥,其余的连通分支就是边双连通分支了。一个有桥的连通图要变成边双连通图的话,
把双连通子图收缩为一个点,形成一颗树。需要加的边为(leaf+1)/2(leaf为叶子结点的个数)
POJ 3177 给定一个连通的无向图G,至少要添加几条边,才能使其变为双连通图。
*/
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std; const int MAXN=;//点数
const int MAXM=;//边数,因为是无向图,所以这个值要 *2
struct Edge{
int to,next;
bool cut;//是否是桥标记
}edge[MAXM];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN],Belong[MAXN];//Belong 数组的值是1~block
int Index,top;
int block;//边双连通块数
bool Instack[MAXN];
int bridge;//桥的数目
void addedge(int u,int v){
edge[tot].to=v;
edge[tot].next=head[u];
edge[tot].cut=false;
head[u]=tot++;
}
void Tarjan(int u,int pre){
int v;
Low[u]=DFN[u]=++Index;
Stack[top++]=u;
Instack[u]=true;
for(int i=head[u];i!=-;i=edge[i].next){
v=edge[i].to;
if(v==pre)continue;
if(!DFN[v]){
Tarjan(v,u);
if(Low[u]>Low[v])Low[u]=Low[v];
if(Low[v]>DFN[u]){
bridge++;
edge[i].cut=true;
edge[i^].cut=true;
}
}
else if(Instack[v]&&Low[u]>DFN[v])
Low[u]=DFN[v];
}
if(Low[u]==DFN[u]){
block++;
do{
v=Stack[--top];
Instack[v]=false;
Belong[v]=block;
}
while(v!=u);
}
}
void init(){
tot=;
memset(head,-,sizeof(head));
}
int du[MAXN];//缩点后形成树,每个点的度数
void solve(int n){
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
Index=top=block=;
Tarjan(,);
int ans=;
memset(du,,sizeof(du));
for(int i=;i<=n;i++)
for(int j=head[i];j!=-;j=edge[j].next)
if(edge[j].cut)
du[Belong[i]]++;
for(int i=;i<=block;i++)
if(du[i]==)
ans++;
//找叶子结点的个数 ans,构造边双连通图需要加边(ans+1)/2
printf("%d\n",(ans+)/);
}
int main(){
int n,m;
int u,v;
while(scanf("%d%d",&n,&m)==){
init();
while(m--){
scanf("%d%d",&u,&v);
addedge(u,v);
addedge(v,u);
}
solve(n);
}
return ;
}

POJ - 3177 Redundant Paths(边双连通分支)(模板)的更多相关文章

  1. Poj 3177 Redundant Paths (双连通分支+节点统计)

    题目描述: 给出一个无向的连通图,问最少加入几条边,才能使所给的图变为无桥的双连通图? 解题思路: 可以求出原图中所有的不包含桥的所有最大连通子图,然后对连通子图进行标记缩点,统计度为1的叶子节点le ...

  2. tarjan算法求桥双连通分量 POJ 3177 Redundant Paths

    POJ 3177 Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12598   Accept ...

  3. POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)

    POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...

  4. POJ 3177 Redundant Paths(边双连通的构造)

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13717   Accepted: 5824 ...

  5. POJ 3177——Redundant Paths——————【加边形成边双连通图】

    Redundant Paths Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  6. POJ 3177 Redundant Paths POJ 3352 Road Construction

    这两题是一样的,代码完全一样. 就是给了一个连通图,问加多少条边可以变成边双连通. 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话,把双连通子图收缩为一个点,形成一颗树 ...

  7. [双连通分量] POJ 3177 Redundant Paths

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13712   Accepted: 5821 ...

  8. poj 3177 Redundant Paths

    题目链接:http://poj.org/problem?id=3177 边双连通问题,与点双连通还是有区别的!!! 题意是给你一个图(本来是连通的),问你需要加多少边,使任意两点间,都有两条边不重复的 ...

  9. poj 3177 Redundant Paths【求最少添加多少条边可以使图变成双连通图】【缩点后求入度为1的点个数】

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11047   Accepted: 4725 ...

随机推荐

  1. CodeForces 556 --Case of Fake Numbers

    B. Case of Fake Numbers time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  2. [NOIP2003] 提高组 洛谷P1039 侦探推理

    题目描述 明明同学最近迷上了侦探漫画<柯南>并沉醉于推理游戏之中,于是他召集了一群同学玩推理游戏.游戏的内容是这样的,明明的同学们先商量好由其中的一个人充当罪犯(在明明不知情的情况下),明 ...

  3. zookeeper学习0

    参考文献: 5分钟让你了解 ZooKeeper 的功能和原理 Zookeeper专题——1.分布式事务(a概述) Zookeeper专题——2.分布式锁-基于Zookeeper的分布式锁

  4. 内存管理(——高质量程序设计语言C/C++第16章)

    内存的分配方式: 1.静态存储区分配:全局变量,static变量等,在程序编译时已经分配了存储内存,在程序运行的整个期间一直存在 2.程序的堆栈上:程序的局部变量,包括程序的形参等,只存在于程序的运行 ...

  5. poj2243+poj1915骑士问题

    2243是骑士问题,八个格子的,BFS,因为要最短路经,所以没有用A*,A*跑不出来,太慢了,因为要搜索到所有解啊!一直更新最优,而BFS,一层一层搜索,第一次得到的便是最短的了!300格子,标记的话 ...

  6. hdu6080(最小环)

    题目 http://acm.hdu.edu.cn/showproblem.php?pid=6080 分析 很妙的思路,将里面的点集当作A,将外面的点集当作B 然后O(n^2)枚举两两B点,设一个是u, ...

  7. windows 平台使用wireshark命令行抓包

    Windows网络流量大,或则需要长时间抓包时,wireshark图形界面使用起来比较麻烦 wireshark 内置 dumpcap命令 Capture interface:  -i <inte ...

  8. @Aspect注解无效

    Pointcut的execution配置正确的话,检查下,是否加了以下jar包 <!-- http://mvnrepository.com/artifact/org.aspectj/aspect ...

  9. android手机rootROM下载地址

    https://download.mokeedev.com/ https://download.lineageos.org/

  10. 我的Android Studio 优化之路

    改动keymap 改动经常使用的快捷键 代码补全(Eclipse: ALT+/) Android Studio中默认用的是Ctrl+Space, 这跟输入法切换冲突.找到Keymap->Main ...