博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[POJ3177]Redundant Paths
阅读量:5172 次
发布时间:2019-06-13

本文共 3048 字,大约阅读时间需要 10 分钟。

[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 71 22 33 42 54 55 65 7

输出示例

2

数据规模及约定

见“试题描述

题解

同。

#include 
#include
#include
#include
#include
#include
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

你可能感兴趣的文章
注意java的对象引用
查看>>
C++ 面向对象 类成员函数this指针
查看>>
NSPredicate的使用,超级强大
查看>>
自动分割mp3等音频视频文件的脚本
查看>>
判断字符串是否为空的注意事项
查看>>
布兰诗歌
查看>>
(转)Tomcat 8 安装和配置、优化
查看>>
(转)Linxu磁盘体系知识介绍及磁盘介绍
查看>>
跨域问题整理
查看>>
[Linux]文件浏览
查看>>
获取国内随机IP的函数
查看>>
Spring Mvc模式下Jquery Ajax 与后台交互操作
查看>>
(转)matlab练习程序(HOG方向梯度直方图)
查看>>
tableView
查看>>
Happy Great BG-卡精度
查看>>
TCP/IP 邮件的原理
查看>>
原型设计工具
查看>>
windows下的C++ socket服务器(4)
查看>>
css3 2d转换3d转换以及动画的知识点汇总
查看>>
计算机改名导致数据库链接的诡异问题
查看>>