【边双连通】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 ...
随机推荐
- NumPy库的基本使用
一.介绍 ——NumPy库是高性能科学计算和数据分析的基础包,它是Pandas及其它各种工具的基础 ——NumPy里的ndarry多维数组对象,与列表的区别是: - 数组对象内的元素类型必须一样 - ...
- jquery分页组件(每页显示多少条)
/** * 功能说明:jPager 分页插件 * 参数说明:pages:[] 分页的控件个数 @id:显示分页的div ID,@showSelectPage: 是否显示当前分页的条目过滤下拉框 * @ ...
- iTOP-IMX6UL 实战项目:ssh 服务器移植到 arm 开发板
实验环境:迅为提供的Ubuntu12.04.2 以及虚拟机 编译器:arm-2009q3 编译器 开发板系统:QT系统 开发板使用手册中给Windows 系统安装了 ssh 客户端,给 Ubunt ...
- Data truncation: Data too long for column 'id' at row 1
Caused by: java.sql.BatchUpdateException: Data truncation: Data too long for column 'titleimg' at ro ...
- Python基础篇 -- 列表
3.2 列表的增删改查 列表使用 [] 来表示,列表中每个元素与元素之间用逗号隔开 列表也有索引和切片 # 切片切出来的也是列表 lst = ["梅西", "内马 ...
- Java获取字符串里面的重复字符
public static void main(String[] args) { String word="天地玄黄宇宙洪荒" + "日月盈昃辰宿列张" + & ...
- lucene4.10.2实例(增删改查)
最新jar和src免费下载:http://download.csdn.net/detail/u011518709/8248403 lucene 包的组成结构:对于外部应用来说索引模块(index)和检 ...
- 文件操作-mkdir
Linux mkdir命令 主要用来创建目录,也可以直接创建多层目录,本文就为大家介绍下 Linux mkdir命令 . 转载自https://www.linuxdaxue.com/linux-com ...
- Linux菜鸟起飞之路【四】绝对路径、相对路径及常用目录
一.绝对路径与相对路径 Linux操作系统中存在着两种路径:绝对路径和相对路径.我们在访问文件或文件夹的时候,其实都是通过路径来操作的.两种路径在实际操作中能起到同等的作用. 在开始具体介绍之前,我们 ...
- Web框架之Django_08 重要组件(form组件、cookie和session组件)
摘要: form组件 cookie组件 session组件 一.form组件 form介绍我们之前在html页面中利用form表单向后端提交数据时候,都需要对用户的输入进行校验,比如校验用户是否输入正 ...