【边双连通】poj 3352 Road Construction
http://poj.org/problem?id=3352
【题意】
给定一个连通的无向图,求最少加多少条边使得这个图变成边双连通图
【AC】
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring> using namespace std;
typedef long long ll;
int n,m;
const int maxn=1e3+;;
const int maxm=*maxn;
struct node
{
int to;
int nxt;
}e[maxm];
int tot;
int head[maxn];
int vis[maxn];
int dfn[maxn];
int id;
int low[maxn];
int du[maxn];
void init()
{
tot=;
memset(head,-,sizeof(head));
memset(dfn,,sizeof(dfn));
id=;
memset(low,,sizeof(low));
memset(du,,sizeof(du));
}
void add(int u,int v)
{
e[tot].to=v;
e[tot].nxt=head[u];
head[u]=tot++;
}
void tarjan(int u,int pa)
{
vis[u]=;
low[u]=dfn[u]=++id;
for(int i=head[u];i!=-;i=e[i].nxt)
{
int v=e[i].to;
if(v==pa) continue;
if(!vis[v])//树边
{
tarjan(v,u);
low[u]=min(low[u],low[v]);
}
else if(vis[v]==)//回退边,vis[v]==2是横向边,不做操作
{
low[u]=min(low[u],dfn[v]);
}
}
vis[u]=;
}
void solve()
{
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
{
if(!vis[i]) tarjan(i,i);
}
for(int u=;u<=n;u++)
{
for(int i=head[u];i!=-;i=e[i].nxt)
{
int v=e[i].to;
if(low[u]!=low[v])
{
du[low[u]]++;
}
}
}
int cnt=;
for(int i=;i<=n;i++)
{
if(du[i]==)
{
cnt++;
}
}
int ans=(cnt+)/;
printf("%d\n",ans); }
int main()
{
while(~scanf("%d%d",&n,&m))
{
init();
int u,v;
for(int i=;i<=m;i++)
{
scanf("%d%d",&u,&v);
add(u,v);
add(v,u);
}
solve();
}
return ;
}
【边双连通】poj 3352 Road Construction的更多相关文章
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
- poj 3352 Road Construction【边双连通求最少加多少条边使图双连通&&缩点】
Road Construction Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10141 Accepted: 503 ...
- POJ 3352 Road Construction 双联通分量 难度:1
http://poj.org/problem?id=3352 有重边的话重边就不被包含在双连通里了 割点不一定连着割边,因为这个图不一定是点连通,所以可能出现反而多增加了双连通分量数的可能 必须要用割 ...
- POJ 3352 Road Construction(边—双连通分量)
http://poj.org/problem?id=3352 题意: 给出一个图,求最少要加多少条边,能把该图变成边—双连通. 思路:双连通分量是没有桥的,dfs一遍,计算出每个结点的low值,如果相 ...
- Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)
http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...
- POJ 3352 Road Construction(边双连通分量,桥,tarjan)
题解转自http://blog.csdn.net/lyy289065406/article/details/6762370 文中部分思路或定义模糊,重写的红色部分为修改过的. 大致题意: 某个企业 ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction
这两题是一样的,代码完全一样. 就是给了一个连通图,问加多少条边可以变成边双连通. 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话,把双连通子图收缩为一个点,形成一颗树 ...
- POJ - 3352 Road Construction(边双连通分支)
1.给定一个连通的无向图G,至少要添加几条边,才能使其变为双连通图. 2.POJ - 3177 Redundant Paths(边双连通分支)(模板) 与这道题一模一样.代码就改了下范围,其他都没动 ...
- 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 ...
随机推荐
- JS 字符串 时间 数字函数操作 事件
字符串 操作 var s="abcdefg" s.tolowerCase() 转小写 s.toupperCase() 转大写 s.substring(2,5) 索引下 ...
- Date/Time Functions and Operators (Postgres)
http://www.postgresql.org/docs/9.1/static/functions-datetime.html Search Documentation: H ...
- nginx 编译某个模板的问题./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library stati
root@hett-PowerEdge-T30:/usr/local/src/nginx-1.9.8# ./configure --prefix=/usr/local/nginx --add-mod ...
- 用函数创建对象、类创建对象,以及使用prototype的好处
用函数创建对象 var CheckObject = function(){}; CheckObject.checkName = function(){ // 检验姓名 }; CheckObject.c ...
- CeontOS6.5安装php环境
港湾云主机重装操作系统之后xshell无法连接:重启ssh:# service sshd restart -bash: vim: command not found:输入 rpm -qa|grep v ...
- 第2节 azkaban调度:17、azkaban的两个服务模式的安装
2.3.3.azkaban两个服务模式安装 1.确认所需软件: Azkaban Web服务安装包 azkaban-web-server-0.1.0-SNAPSHOT.tar.gz Azkaban执行服 ...
- c语言产生随机数的方法
在C语言中,rand()函数可以用来产生随机数,但是这不是真真意义上的随机数,是一个伪随机数,是根据一个数,我们可以称它为种子,为基准以某个递推公式推算出来的一系数,当这系列数很大的时候,就符合正态公 ...
- PAT (Basic Level) Practise (中文)-1028. 人口普查(20)
PAT (Basic Level) Practise (中文)-1028. 人口普查(20) http://www.patest.cn/contests/pat-b-practise/1028 某 ...
- 洛谷 P1019 单词接龙 (DFS)
题目传送门 当时一看到这题,蒟蒻的我还以为是DP,结果发现标签是搜索-- 这道题的难点在于思路和预处理,真正的搜索实现起来并不难.我们可以用一个贪心的思路,开一个dic数组记录每个单词的最小重复部分, ...
- please upgrade your plan to create a new private reposiory
请升级你的计划来创建一个新的私人仓库 提交仓库到github,要公开,除非买他们服务,所以把勾去掉就好了keep this code private