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

2、POJ - 3177 Redundant Paths(边双连通分支)(模板)  与这道题一模一样。代码就改了下范围,其他都没动。。。

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 - 3352 Road Construction(边双连通分支)的更多相关文章

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

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

  2. poj 3352 Road Construction【边双连通求最少加多少条边使图双连通&&缩点】

    Road Construction Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10141   Accepted: 503 ...

  3. Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)

     http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...

  4. POJ 3177 Redundant Paths & POJ 3352 Road Construction(双连通分量)

    Description In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numb ...

  5. POJ 3177 Redundant Paths POJ 3352 Road Construction

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

  6. poj 3352 Road Construction(边双连通分量+缩点)

    题目链接:http://poj.org/problem?id=3352 这题和poj 3177 一样,参考http://www.cnblogs.com/frog112111/p/3367039.htm ...

  7. POJ 3352 Road Construction 双联通分量 难度:1

    http://poj.org/problem?id=3352 有重边的话重边就不被包含在双连通里了 割点不一定连着割边,因为这个图不一定是点连通,所以可能出现反而多增加了双连通分量数的可能 必须要用割 ...

  8. POJ 3352 Road Construction(边—双连通分量)

    http://poj.org/problem?id=3352 题意: 给出一个图,求最少要加多少条边,能把该图变成边—双连通. 思路:双连通分量是没有桥的,dfs一遍,计算出每个结点的low值,如果相 ...

  9. 【边双连通】poj 3352 Road Construction

    http://poj.org/problem?id=3352 [题意] 给定一个连通的无向图,求最少加多少条边使得这个图变成边双连通图 [AC] //#include<bits/stdc++.h ...

随机推荐

  1. 解决Can’t finish GitHub sharing process Successfully created project ‘GitHubDemo’ on GitHub

    Can't finish GitHub sharing process        Successfully created project 'KeyWordsFrameWork' on GitHu ...

  2. String类型根据逗号分隔转为list

    String ids = pd.getString("IDS");//从pd里取出字符串 List idList = Arrays.asList(ids.split(", ...

  3. vue.js基础知识总结

    初始化一个项目 npm init -y 安装一些依赖 npm install 名称 --save 例如 npm install vue axios bootstrap --save --save 表示 ...

  4. 大话数据结构——KMP算法(还存在问题)

    http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html /*#include& ...

  5. hdu 5200 Trees [ 排序 离线 2指针 ]

    传送门 Trees  Accepts: 156  Submissions: 533  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 655 ...

  6. msp430入门编程24

    msp430中C语言的扩展--段的使用 msp430入门学习 msp430入门编程

  7. linux 常见名词及命令(一)

    linux  PK  wondows 稳定且有效率.免费或少许费用.漏洞少且修补快.多任务多用户. 安全的用户及文件权限策略.适合小内核程序的嵌入系统.相对不耗资源. 热门的开源系统 红帽企业系统(R ...

  8. poj2767,单向连通图判定,缩点+重新建图+新图DFS

    /*该题被博客里标记为中等题,30分钟内1A,掌握了算法就简单了,单向连通图判定,单向连通图缩点 后必然唯一存在出度为0的点和入度为0的点,并且从入度为0的点出发,可以遍历所有点后到达出度为0点 (一 ...

  9. ACM-ICPC 2018 焦作赛区网络预赛 H、L

    https://nanti.jisuanke.com/t/31721 题意 n个位置 有几个限制相邻的三个怎么怎么样,直接从3开始 矩阵快速幂进行递推就可以了 #include <bits/st ...

  10. 洛谷——P2068 统计和

    P2068 统计和 题目描述 给定一个长度为n(n<=100000),初始值都为0的序列,x(x<=10000)次的修改某些位置上的数字,每次加上一个数,然后提出y (y<=1000 ...