poj3177 无向连通图加多少条边变成边双连通图
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 15752 | Accepted: 6609 |
Description
Given a description of the current set of R (F-1 <= R <= 10,000) paths that each connect exactly two different fields, determine the minimum number of new paths (each of which connects exactly two fields) that must be built so that there are at least two separate routes between any pair of fields. Routes are considered separate if they use none of the same paths, even if they visit the same intermediate field along the way.
There might already be more than one paths between the same pair of fields, and you may also build a new path that connects the same fields as some other path.
Input
Lines 2..R+1: Each line contains two space-separated integers which are the fields at the endpoints of some path.
Output
Sample Input
7 7
1 2
2 3
3 4
2 5
4 5
5 6
5 7
Sample Output
2
注意重边
不能通过low值判断两个点在一个连通分量内,
因为这样的数据 1-6都在一个联通块内,但6的low值和其他不同。
6 7
1 2
2 3
3 4
4 6
6 2
4 5
5 1
但是貌似 没有影响?。因为虽然6的low值有变化,但是他不可能是叶节点,所以用low值水过去也是可以的吧 就是缩点后找叶子结点的数目+1/2就是答案
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
bool mp[N][N];
int head[N],dfn[N],low[N],cont[N];
int tot,cnt;
struct node{
int next,to;
}e[N<<];
void add(int u,int v){
e[tot].to=v;e[tot].next=head[u];head[u]=tot++;
e[tot].to=u;e[tot].next=head[v];head[v]=tot++;
}
void Tajan(int u,int fa){
dfn[u]=low[u]=++cnt;
for(int i=head[u];i+;i=e[i].next){
int v=e[i].to;
if(v==fa) continue;
if(!dfn[v]) {
Tajan(v,u);
low[u]=min(low[v],low[u]);
}
else low[u]=min(low[u],dfn[v]);
}
}
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
int u,v;
memset(head,-,sizeof(head));
memset(mp,,sizeof(mp));
memset(cont,,sizeof(cont));
tot=cnt=;
while(m--){
scanf("%d%d",&u,&v);
if(mp[u][v]) continue;
add(u,v);
mp[u][v]=mp[v][u]=;
}
Tajan(,);
for(int i=;i<=n;++i)
for(int j=head[i];j+;j=e[j].next){
int v=e[j].to;
if(low[v]!=low[i])
++cont[low[i]];
}
int ans=;
for(int i=;i<=n;++i)
if(cont[i]==) ++ans;
printf("%d\n",(ans+)/);
}
}
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
bool mp[N][N];
int head[N],dfn[N],low[N],cont[N],bl[N],q[N];
int tot,cnt,scnt,l;
struct node{
int next,to;
}e[N<<];
void add(int u,int v){
e[tot].to=v;e[tot].next=head[u];head[u]=tot++;
e[tot].to=u;e[tot].next=head[v];head[v]=tot++;
}
void Tajan(int u,int fa){
q[l++]=u;
dfn[u]=low[u]=++cnt;
for(int i=head[u];i+;i=e[i].next){
int v=e[i].to;
if(v==fa) continue;
if(!dfn[v]) {
Tajan(v,u);
low[u]=min(low[v],low[u]);
}
else low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u]){
int t;
++scnt;
do{
t=q[--l];
bl[t]=scnt;
}while(t!=u);
}
}
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
int u,v;
memset(head,-,sizeof(head));
memset(mp,,sizeof(mp));
memset(cont,,sizeof(cont));
l=scnt=tot=cnt=;
while(m--){
scanf("%d%d",&u,&v);
if(mp[u][v]) continue;
add(u,v);
mp[u][v]=mp[v][u]=;
}
Tajan(,);
for(int i=;i<=n;++i)
for(int j=head[i];j+;j=e[j].next){
int v=e[j].to;
if(bl[v]!=bl[i])
++cont[bl[i]];
}
int ans=;
for(int i=;i<=n;++i)
if(cont[i]==) ++ans;
printf("%d\n",(ans+)/);
}
}
poj3177 无向连通图加多少条边变成边双连通图的更多相关文章
- poj 3352 Road Construction【边双连通求最少加多少条边使图双连通&&缩点】
Road Construction Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10141 Accepted: 503 ...
- ASP无惧上传类不能上传中文双引号文件及ASP函数InStr存在bug
ASP无惧上传类不能上传中文双引号文件及ASP函数InStr存在bug 近日发现eWebEditor V2.8 asp 版本上传文件文件名不能包含中文双引号,发现eWebEditor使用ASP“无惧上 ...
- 采用formdata做跨域的、无刷新、带进度条的文件上传
以前做无刷新上传,都要用iframe,如果想有进度条,就千难万难,不得不用flash等插件来实现. 现在HTML5终于普及了,筒子们不用再那么痛苦了. 所有这一切都变得异常简单!! 不信?且看如下代码 ...
- spin.js无图片实现loading进度条,支持但非依赖jquery
特点: 1.无图片,无外部CSS 2.无依赖(支持jQuery,但非必须) 3.高度可配置 4.分辨率无关 5.旧版本IE不支持时,采用VML支持 6.使用关键帧动画,采用setTimeout() 7 ...
- nyoj42——连通图加欧拉(连通图板子)dfs
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...
- Hive 组内计无重复数,追加每条记录后面
今天无意中碰到一个很简单的计算逻辑,但是用hive想了一大会才实现. 示例表数据: 需求逻辑: 给每条记录追加一个字段,用于统计按照p1和p2字段分组后,每个组中的num的数目(去重后的count). ...
- 无图无定位新版css步骤条兼容ie6+
<ul class="ui-step list-unstyled"> <li class="step-item"><b class ...
- POJ3177,/3352.求最少添加多少边使无向图边双连通
俩个题一样.tarjan算法应用,开始求桥,WA,同一个边双连通分量中low值未必都相同,不能用此来缩点.后来用并查集来判断,若不是桥,则在一个双连通分量中,并之,后边再查,将同一个双连通分量中的点通 ...
- poj 3177 Redundant Paths【求最少添加多少条边可以使图变成双连通图】【缩点后求入度为1的点个数】
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11047 Accepted: 4725 ...
随机推荐
- 【深入AQS原理】我画了35张图就是为了让你深入 AQS
申明 本文首发自公众号:程序员cxuan,此文章为本人投稿文章.已经和cxuan沟通,文章投递公众号,博客平台我自己发布可标记为原创. 此文章肝了很久,图片较多,希望大家喜欢. 另外,感兴趣的小伙伴可 ...
- 阿里巴巴年薪800k大数据全栈工程师成长记
大数据全栈工程师一词,最早出现于Facebook工程师Calos Bueno的一篇文章 - Full Stack (需fanqiang).他把全栈工程师定义为对性能影响有着深入理解的技术通才.自那以后 ...
- 谈谈JavaScript中的变量、指针和引用
1.变量 我们可能产生这样一个疑问:编程语言中的变量到底是什么意思呢? 事实上,当我们定义了一个变量a时,就是在存储器中指定了一组存储单元,并将这组存储单元命名为a.变量a的值实际上描述的是这组存储单 ...
- ASP.NET Core WebApi(01)项目建立
前言:前一段时间学习了ASP.NET Core,决定写个简单的项目,旨在消化所学内容,并记录过程中遇到的问题.本章是第一篇,内容为项目的建立 一.准备工作 安装Visual Studio时,默认会安装 ...
- .user.ini 无法修改/删除 怎么办?
首先 了解chattr命令: Linux chattr命令用于改变文件属性. 这项指令可改变存放在ext2文件系统上的文件或目录属性,这些属性共有以下8种模式: a:让文件或目录仅供附加用途.b:不更 ...
- Linux中的程序和进程,PID和PPID
环境:Vmware Workstation:CentOS-6.4-x86_64 程序和进程: 1.程序:程序是静止的,程序就是磁盘上的一个文件. 2.进程:进程是一个正在执行的程序的实例. 3.进程是 ...
- vue js手机端滑到某一个位置时固定位置显示
1.HTML <div id="searchBar"><ul class="items_filter" :class="search ...
- 多阶段构建Golang程序Docker镜像
Docker简介 Docker是基于Linux容器技术(LXC),使用Go语言实现的开源项目,诞生于2013年,遵循Apache2.0协议.Docker自开源后,受到广泛的关注和讨论. Docker在 ...
- Phoenix and Distribution(字典序贪心)
\(给定一串字母,分成k份,使得最大字典序最小.(字母可以任意组合)\) \(------------------------------issue~------------------------\ ...
- struts2入门教学
我的博客地址:https://blog.csdn.net/qq_41907991 首先介绍一下struts2使用的基本步骤: 1.导入相关的 jar 文件 2.需要在 web.xml 文件中配置一个 ...