Redundant Paths
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 15752   Accepted: 6609

Description

In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1..F) to another field, Bessie and the rest of the herd are forced to cross near the Tree of Rotten Apples. The cows are now tired of often being forced to take a particular path and want to build some new paths so that they will always have a choice of at least two separate routes between any pair of fields. They currently have at least one route between each pair of fields and want to have at least two. Of course, they can only travel on Official Paths when they move from one field to another.

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

Line 1: Two space-separated integers: F and R

Lines 2..R+1: Each line contains two space-separated integers which are the fields at the endpoints of some path.

Output

Line 1: A single integer that is the number of new paths that must be built.

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 无向连通图加多少条边变成边双连通图的更多相关文章

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

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

  2. ASP无惧上传类不能上传中文双引号文件及ASP函数InStr存在bug

    ASP无惧上传类不能上传中文双引号文件及ASP函数InStr存在bug 近日发现eWebEditor V2.8 asp 版本上传文件文件名不能包含中文双引号,发现eWebEditor使用ASP“无惧上 ...

  3. 采用formdata做跨域的、无刷新、带进度条的文件上传

    以前做无刷新上传,都要用iframe,如果想有进度条,就千难万难,不得不用flash等插件来实现. 现在HTML5终于普及了,筒子们不用再那么痛苦了. 所有这一切都变得异常简单!! 不信?且看如下代码 ...

  4. spin.js无图片实现loading进度条,支持但非依赖jquery

    特点: 1.无图片,无外部CSS 2.无依赖(支持jQuery,但非必须) 3.高度可配置 4.分辨率无关 5.旧版本IE不支持时,采用VML支持 6.使用关键帧动画,采用setTimeout() 7 ...

  5. nyoj42——连通图加欧拉(连通图板子)dfs

    一笔画问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...

  6. Hive 组内计无重复数,追加每条记录后面

    今天无意中碰到一个很简单的计算逻辑,但是用hive想了一大会才实现. 示例表数据: 需求逻辑: 给每条记录追加一个字段,用于统计按照p1和p2字段分组后,每个组中的num的数目(去重后的count). ...

  7. 无图无定位新版css步骤条兼容ie6+

    <ul class="ui-step list-unstyled"> <li class="step-item"><b class ...

  8. POJ3177,/3352.求最少添加多少边使无向图边双连通

    俩个题一样.tarjan算法应用,开始求桥,WA,同一个边双连通分量中low值未必都相同,不能用此来缩点.后来用并查集来判断,若不是桥,则在一个双连通分量中,并之,后边再查,将同一个双连通分量中的点通 ...

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

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

随机推荐

  1. 【Linux常见命令】vi,vim命令

    所有的 Unix Like 系统都会内建 vi 文书编辑器,其他的文书编辑器则不一定会存在. 但是目前我们使用比较多的是 vim 编辑器. vim 具有程序编辑的能力,可以主动的以字体颜色辨别语法的正 ...

  2. 团队中的 Node.js 具体实践

    前天,我们公司前端团队的几个人一起去大搜车参加了芋头所组织的「搜车 Node Party」.这是我第一次参加与 Node.js 相关的线下聚会,如果不算「杭JS」的话. 聚会现场 这次聚会的主题全部是 ...

  3. Math.Round和四舍五入

    Math.Round方法并不是像想象中的四舍五入, 可以从下面的输出结果看出来: Math.Round(3.44, 1); //Returns 3.4. Math.Round(3.45, 1); // ...

  4. U盘安装Proxmox VE(一)

    转自我的个人博客:U盘安装Proxmox VE(一) 年前搞了个星际蜗牛B款机箱,利用手头之前海淘dq77kb组装了个四盘位的Server. 组装完毕后,直接在实体机安装了centos 7.使用这几个 ...

  5. flink系列-10、flink保证数据的一致性

    本文摘自书籍<Flink基础教程> 一.一致性的三种级别 当在分布式系统中引入状态时,自然也引入了一致性问题.一致性实际上是“正确性级别”的另一种说法,即在成功处理故障并恢复之后得到的结果 ...

  6. 算法——Java实现队列

    顺序队列: 概念: 队列是一种先进先出的线性表,只允许在一端插入,另一端删除.允许插入的一端称为队尾,允许删除的一端称为队头 顺序队列的实现: import org.junit.jupiter.api ...

  7. Codeforces 1332 D. Walk on Matrix(构造矩阵)

    怎么构造呢? \(首先我们不可能去构造一个2000*2000的矩阵,那太复杂了\) \(也许我们可以看看2*2的矩阵??\) \[\left[ \begin{matrix} x&y\\ z&a ...

  8. Spring源码阅读 之 搭建源码阅读环境(IDEA)

    检出源码: GitHub:https://github.com/spring-projects/spring-framework.git 可以按如下步骤:(须确保Git已正确安装) Git正确安装后, ...

  9. 003_python的str切片,str常用操作方法,for循环,集合,深浅copy

    基础数据类型 基础数据类型,有7种类型,存在即合理. 1.int 整数 主要是做运算的 .比如加减乘除,幂,取余  + - * / ** %... 2.bool布尔值 判断真假以及作为条件变量 3.s ...

  10. 带你100% 地了解 Redis 6.0 的客户端缓存

    近日 Redis 6.0.0 GA 版本发布,这是 Redis 历史上最大的一次版本更新,包括了客户端缓存 (Client side caching).ACL.Threaded I/O 和 Redis ...