[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. Linux的centos7.2部署rocketMq3.5.8
  2. 静态分配和动态分配内存的区别
  3. Python+Opencv实现多种形状的检测
  4. cf246E. Blood Cousins Return
  5. 简述python的特性_Python的特性概要
  6. 高通骁龙cpu排行_最新手机性能排行榜出炉:高通骁龙865霸榜,前十不见华为!...
  7. ArrayList Vector
  8. python中基例_python | 自定义函数
  9. 号码被标记,各平台取消方法
  10. Huffman-哈夫曼编码算法详解
  11. Vue + Spring Boot 项目实战(十四):用户认证方案与完善的访问拦截
  12. Python 用Pygame写一个Flappy Bird经典小游戏
  13. 切片器可以设置日期格式?_如何分秒必争--浅淡时间切片器
  14. SingleShot姿态估计部署教程
  15. 2020年技术领导者需要关注的5个关键领域
  16. 不同坐标系下角速度_轨道、重力场与坐标系的混乱关系
  17. 推荐一款适合程序员的思维工具(功能相当于xmind+有道云)
  18. 软件工程实训有必要吗_软件工程实训心得体会
  19. 注册交管12123服务器异常,交管12123提示服务异常怎么解决
  20. 友推微信分享失败解决办法

热门文章

  1. 关于SQLyog创建的数据库不显示的问题
  2. nginx负载均衡的5种策略(转载)
  3. BootStrap中常用样式类
  4. 【Flask】通过Flask_login实现用户登录
  5. hihocoder-Week195-奖券兑换
  6. .NET 4.0 使用 asyn await
  7. android 禁用和开启四大组件的方法(setComponentEnabledSetting )
  8. 转载:你需要知道的16个Linux服务器监控命令
  9. 什么是相关性以及为什么需要初始化它?
  10. 为imageView添加图片实现动画