POJ 1442 Road Construction 最小路径

标签: c++ poj 二分图
286人阅读 评论(0) 收藏 举报
E - Road Construction
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u


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.


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.


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

Sample Input

Sample Input 1
10 12
1 2
1 3
1 4
2 5
2 6
5 6
3 7
3 8
7 8
4 9
4 10
9 10

Sample Input 2
3 3
1 2
2 3
1 3

Sample Output

Output for Sample Input 1

Output for Sample Input 2



#pragma warning(disable:4786)//使命名长度不受限制
#pragma comment(linker, "/STACK:102400000,102400000")//手工开栈
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 205
#define mod 1000000007
#define INF 0x3f3f3f3f //int 最大值
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI  acos(-1.0)
#define E  exp(1)
using namespace std;
bool bmap[maxn][maxn];
bool bmask[maxn];
int pre[maxn];
int loop,n,m,x,y;
void init(){
int findpath(int u){
                return 1 ;
    return 0;
int Maxmatch(){
    int res(0);
    return res;
int main(){
    rd (loop);
    return 0;
3 4
1 3
2 3
1 3
1 2
2 3


POJ 3352 Road Construction

题目大意: 给定图G,求最少加多少边可以成为双连通图。 解题思路: 1、求图G中的双连通分量。 2、每一个双联通分量缩成一个点,形成一棵树。 3、计算出叶子节点的个数,需要加的边的数...
  • lin375691011
  • lin375691011
  • 2014年01月25日 21:18
  • 6112

AOJ 2249 Road Construction(双权值最短路)

Road Construction King Mercer is the king of ACM kingdom. There are one capital and some cities...
  • qq_26658823
  • qq_26658823
  • 2016年09月02日 08:06
  • 207

POJ 1442 (treap)

Black Box Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9871   Acce...
  • qq_24489717
  • qq_24489717
  • 2016年03月28日 17:20
  • 264

HDU 3917 Road constructions (最小割---最大权闭包)经典

Road constructions Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe...
  • u010372095
  • u010372095
  • 2015年08月17日 15:09
  • 647

CF 330B Road Construction 构造路径 水题

B. Road Construction time limit per test 2 seconds memory limit per test 256 megabytes input s...
  • ipqhjjybj
  • ipqhjjybj
  • 2013年07月21日 00:09
  • 1773

POJ 3352: Road Construction

题目链接:http://poj.org/problem?id=2186 题目大意: 问至少加多少边,可以使得图变成双联通的。 算法: 双联通模板题。 比较特殊的是有重边。 那么在访问每条边的时...
  • frog1902
  • frog1902
  • 2013年07月27日 23:22
  • 823

POJ 1785 Binary Search Heap Construction 【笛卡尔树构造,线段树RMQ(Range Max/Min Query)】

题目注意: 两个要求,1. 第一关键字满足搜索序,2. 第二关键字满足堆的性质。 这道题目的标准(简单)解法:笛卡尔树。 但是还有: 分治+RMQ, 其中,RMQ问题有两种方法:线段树和Spars...
  • yang_7_46
  • yang_7_46
  • 2013年01月24日 20:24
  • 3244

poj 3352 Road Construction

与poj 3177 类似,不过此题没有重边,所以可以用 vector 来存边。
  • u013467535
  • u013467535
  • 2014年11月25日 14:28
  • 529

POJ 3352 Road Construction

Road Construction Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10183   Accepte...
  • zp___waj
  • zp___waj
  • 2015年11月19日 21:18
  • 248

POJ 3352 Road Construction解题报告

  • cicirise
  • cicirise
  • 2009年04月18日 09:58
  • 1465
    访问量: 40万+
    积分: 1万+
    排名: 1496