博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3352 Road Construction(图论-tarjan)
阅读量:4594 次
发布时间:2019-06-09

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

Road Construction
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 8647   Accepted: 4318

Description

It's almost summer time, and that means that it's almost summer construction time! This year, the good people who are in charge of the roads on the tropical island paradise of Remote Island would like to repair and upgrade the various roads that lead between the various tourist attractions on the island.

The roads themselves are also rather interesting. Due to the strange customs of the island, the roads are arranged so that they never meet at intersections, but rather pass over or under each other using bridges and tunnels. In this way, each road runs between two specific tourist attractions, so that the tourists do not become irreparably lost.

Unfortunately, given the nature of the repairs and upgrades needed on each road, when the construction company works on a particular road, it is unusable in either direction. This could cause a problem if it becomes impossible to travel between two tourist attractions, even if the construction company works on only one road at any particular time.

So, the Road Department of Remote Island has decided to call upon your consulting services to help remedy this problem. It has been decided that new roads will have to be built between the various attractions in such a way that in the final configuration, if any one road is undergoing construction, it would still be possible to travel between any two tourist attractions using the remaining roads. Your task is to find the minimum number of new roads necessary.

Input

The first line of input will consist of positive integers n and r, separated by a space, where 3 ≤ n ≤ 1000 is the number of tourist attractions on the island, and 2 ≤ r ≤ 1000 is the number of roads. The tourist attractions are conveniently labelled from 1 to n. Each of the following r lines will consist of two integers, v and w, separated by a space, indicating that a road exists between the attractions labelled v and w. Note that you may travel in either direction down each road, and any pair of tourist attractions will have at most one road directly between them. Also, you are assured that in the current configuration, it is possible to travel between any two tourist attractions.

Output

One line, consisting of an integer, which gives the minimum number of roads that we need to add.

Sample Input

Sample Input 110 121 21 31 42 52 65 63 73 87 84 94 109 10Sample Input 23 31 22 31 3

Sample Output

Output for Sample Input 12Output for Sample Input 20

Source

题目大意:

给定n个点m条边的无向连通图,问你至少添加多少条边,使得这个图去掉任意一条边依然连通。

解题思路:

首先环中的边去掉依然连通,所以环缩成点,然后将度数为1的点肯定要两两相连,否则去掉这个点所在的边就肯定不连通了。

因此,答案就是:(度数为1的点的个数+1)/ 2

解题代码:

#include 
#include
#include
#include
using namespace std;const int maxm=510000;const int maxn=1100;struct edge{ int u,v,next; edge(int u0=0,int v0=0){ u=u0;v=v0; }}e[maxm];int n,m,head[maxn],color[maxn],dfn[maxn],low[maxn],cnt,nc,index,num[maxn];bool mark[maxn];vector
vec;void addedge(int u,int v){ e[cnt]=edge(u,v);e[cnt].next=head[u];head[u]=cnt++;}void input(){ vec.clear(); cnt=nc=index=0; for(int i=0;i<=n;i++){ color[i]=head[i]=-1; mark[i]=false; num[i]=dfn[i]=0; } for(int i=0;i

转载于:https://www.cnblogs.com/toyking/p/3893143.html

你可能感兴趣的文章
编写clearedit的安卓控件
查看>>
Atitit.ati dwr的原理and设计 attilax 总结 java php 版本
查看>>
Atitit. camel分词器 分词引擎 camel拆分 的实现设计
查看>>
Atitit 深入了解UUID含义是通用唯一识别码 (Universally Unique Identifier),
查看>>
输入和输出
查看>>
shell-逐行读取文件
查看>>
VS Code 屏蔽.meta文件
查看>>
《javascript设计模式》笔记之第五章:单体模式
查看>>
《javascript设计模式》笔记之第六章:方法的链式调用
查看>>
VC++6.0环境下调试c语言代码的方法和步骤_附图
查看>>
20160222深夜 支撑与阻力的问题,突破要不要买,回踩要不要接
查看>>
Already tried 0 time(s); retry policy is RetryUpToMaximumCountWithFixedSleep解决方法
查看>>
学习资料下载地址
查看>>
序列化和反序列化
查看>>
Net 常用资源
查看>>
tomcat7以上的版本,400BadRequest
查看>>
js跳转页面方法
查看>>
GObject消息系统之Closures
查看>>
救命的PHP代码
查看>>
MMORPG大型游戏设计与开发(客户端架构 part2 of vgui)
查看>>