[POJ3177]Redundant Paths

试题描述

In order to get from one of the \(F (1 \le F \le 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 \le R \le 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.

输入

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.

输出

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

输入示例

7 7
1 2
2 3
3 4
2 5
4 5
5 6
5 7

输出示例

2

数据规模及约定

见“试题描述

题解

同POJ3352。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
#define rep(i, s, t) for(int i = (s); i <= (t); i++)
#define dwn(i, s, t) for(int i = (s); i >= (t); i--)int read() {int x = 0, f = 1; char c = getchar();while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }return x * f;
}#define maxn 5010
#define maxm 20010int n, m, head[maxn], nxt[maxm], to[maxm], id[maxm];void AddEdge(int a, int b, int _id) {to[++m] = b; nxt[m] = head[a]; id[m] = _id; head[a] = m;swap(a, b);to[++m] = b; nxt[m] = head[a]; id[m] = _id; head[a] = m;return ;
}int clo, dfn[maxn], low[maxn], cntb, bcno[maxn], S[maxn], top, deg[maxn];
void dfs(int u, int fae) {dfn[u] = low[u] = ++clo;S[++top] = u;for(int e = head[u]; e; e = nxt[e]) if(id[e] != fae) {if(dfn[to[e]]) low[u] = min(low[u], dfn[to[e]]);else dfs(to[e], id[e]), low[u] = min(low[u], low[to[e]]);}if(low[u] == dfn[u]) {cntb++;while(S[top] != u) bcno[S[top--]] = cntb;bcno[S[top--]] = cntb;}return ;
}int main() {n = read(); int M = read();rep(i, 1, M) {int a = read(), b = read();AddEdge(a, b, i);}dfs(1, 0);rep(u, 1, n)for(int e = head[u]; e; e = nxt[e]) if(bcno[u] < bcno[to[e]])deg[bcno[u]]++, deg[bcno[to[e]]]++;int cnt = 0;rep(u, 1, n) cnt += deg[u] == 1;printf("%d\n", cnt + 1 >> 1);return 0;
}

转载于:https://www.cnblogs.com/xiao-ju-ruo-xjr/p/7808911.html

[POJ3177]Redundant Paths相关推荐

  1. POJ3177 Redundant Paths

    POJ3177 Redundant Paths 文章目录 Description 题意: 题解: 代码: Time Limit: 1000MS Memory Limit: 65536K Total S ...

  2. [POJ3177]Redundant Paths(双联通)

    在看了春晚小彩旗的E技能(旋转)后就一直在lol--额抽点时间撸一题吧-- Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Tota ...

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

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

  4. Redundant Paths POJ - 3177(tarjan+边双连通分量)

    题意: 有n个牧场,要求从一个牧场到另一个牧场,要求至少要有2条独立的路可以走.现已有m条路,求至少要新建多少条路,使得任何两个牧场之间至少有两条独立的路.两条独立的路是指:没有公共边的路,但可以经过 ...

  5. 【POJ - 3177】Redundant Paths(边双连通分量,去重边)

    题干: In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1.. ...

  6. POJ 3177 Redundant Paths(边双联通分量)

    题目描述: In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1 ...

  7. POJ - 3177 Redundant Paths 双联通补边

    题目链接 题意:给出一个多条边问需要加几条变才能变成双连通图. 首先要缩点,缩点之后就是变成了一个没有强连通分量的图,这时候只需要统计入度为1的点有多少个,然后通过观察发现将点两两连接即可,answe ...

  8. POJ 3177 Redundant Paths (边双连通+缩点)

    <题目链接> <转载于 >>>  > 题目大意: 有n个牧场,Bessie 要从一个牧场到另一个牧场,要求至少要有2条独立的路可以走.现已有m条路,求至少要新 ...

  9. poj 3177 Redundant Paths

    双连通分量 题意:给一个无向图,问要添加多少条边形成边双连通分量.注意图一开始是连通的,所以只要从一个点开始dfs一次就行了,另外这图有重边,(1,2)(2,1)这样,则1,2就形成了一个边双连通分量 ...

  10. 无向图强联通分量-洛谷 P2860 [USACO06JAN]冗余路径Redundant Paths

    https://www.luogu.org/problem/show?pid=2860 这个就是无向图的强联通: 有向图的两点再一个分量里,是x可以到y,y也可到x: 但无向图本来就是双向的,所以我们 ...

最新文章

  1. android studio 链接编辑,Android Studio怎么连接手机测试程序?
  2. MySQL多表事务课堂笔记
  3. (转)互联网——降级论
  4. 记一次生产数据库系统内存使用过高的案例
  5. 3.6 - Maya Commands: setAttr
  6. java中substring与substr的用法
  7. 罗森伯格2013中国数据中心峰会—长春站
  8. Algs4-1.5.11实现加权quick-find算法
  9. web of science,SSCI索引,带你入门!
  10. python求绝对值_python求绝对值
  11. 误格式化硬盘数据怎么恢复好
  12. 邮箱登录名身份证号码等验证
  13. 电气潮流运算Matlab怎么编程,基于Matlab的电力系统潮流编程计算
  14. 苹果手机白屏_安卓卡顿苹果闪退,手机换代的动力原来是这些
  15. Django和Flask区别
  16. 华为HCNA之SNMP基础配置实验
  17. OSG3.6.3_X64_Collada Dae插件VS2017详细编译步骤
  18. 关于本人上传的资源Win98WinXPWin7整合包虚拟机Alpha1
  19. 易班优课YOOC考试解除禁止查卷
  20. 送餐机器人 | 美格智能5G智能模组助力无人送餐“如有神助”

热门文章

  1. vue基础之样式绑定(class,style)
  2. 十四、final关键字
  3. 2.8.PHP7.1 狐教程-【控制语句 Switch】
  4. Google 的核心 Java 库 guava 常用工具类
  5. Android 四大组件 之 服务(Service)
  6. sql 截取字符串:
  7. 阶段3 1.Mybatis_01.Mybatis课程介绍及环境搭建_07.环境搭建的注意事项
  8. node koa2 玩起来都是中间件啊
  9. jhipster初接触
  10. [No0000DD]C# StringEx 扩展字符串类 类封装