http://poj.org/problem?id=3177

题目大意:给你几个点和几条边   求你能加几条边  就可以让每一个点到达任意点都有两种方法。

Description

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

Input

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.

Output

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

Sample Input

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

Sample Output

2

Hint

Explanation of the sample:

One visualization of the paths is:

   1   2   3
+---+---+
| |
| |
6 +---+---+ 4
/ 5
/
/
7 +

Building new paths from 1 to 6 and from 4 to 7 satisfies the conditions.

   1   2   3
+---+---+
: | |
: | |
6 +---+---+ 4
/ 5 :
/ :
/ :
7 + - - - -

Check some of the routes: 
1 – 2: 1 –> 2 and 1 –> 6 –> 5 –> 2 
1 – 4: 1 –> 2 –> 3 –> 4 and 1 –> 6 –> 5 –> 4 
3 – 7: 3 –> 4 –> 7 and 3 –> 2 –> 5 –> 7 
Every pair of fields is, in fact, connected by two routes.

It's possible that adding some other path will also solve the problem (like one from 6 to 7). Adding two paths, however, is the minimum.

 
 
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector> using namespace std;
#define N 20000 int low[N],dfn[N],n,fa[N],Stack[N],belong[N],Is[N],aa[N];
int Time,top,ans;
vector<vector <int> >G; void Inn()
{
G.clear();
G.resize(n+);
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(fa,,sizeof(fa));
memset(belong,,sizeof(belong));
memset(Stack,,sizeof(Stack));
memset(Is,,sizeof(Is));
memset(aa,,sizeof(aa));
Time=top=ans=;
} void Tarjin(int u,int f)
{
dfn[u]=low[u]=++Time;
Stack[top++]=u;
Is[u]=;
fa[u]=f;
int len=G[u].size(),v;
for(int i=; i<len; i++)
{
v=G[u][i];
if(!dfn[v])
{
Tarjin(v,u);
low[u]=min(low[u],low[v]);
}
else if(f!=v)
low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u])
{
ans++;
do
{
v=Stack[--top];
belong[v]=ans;
Is[v]=;
}while(v!=u);
}
} int main()
{
int m,a,b,i,sum;
while(scanf("%d %d",&n,&m)!=EOF)
{
sum=;
Inn();
for(i=;i<=m;i++)
{
scanf("%d %d",&a,&b);
G[a].push_back(b);
G[b].push_back(a);
}
for(i=;i<=n;i++)
{
if(!dfn[i])
Tarjin(i,);
}
for(i=;i<=n;i++)
{
int v=fa[i];
if(belong[i]!=belong[v]&&v!=)
{
aa[belong[i]]++;
aa[belong[v]]++;
}
}
for(i=;i<=ans;i++)
{
if(aa[i]==)
sum++;
}
printf("%d\n",(sum+)/);
}
return ;
}

Redundant Paths-POJ3177(强连通缩点)的更多相关文章

  1. POJ3177 Redundant Paths —— 边双联通分量 + 缩点

    题目链接:http://poj.org/problem?id=3177 Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total ...

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

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

  3. poj 3177 Redundant Paths【求最少添加多少条边可以使图变成双连通图】【缩点后求入度为1的点个数】

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11047   Accepted: 4725 ...

  4. POJ3177 Redundant Paths 双连通分量

    Redundant Paths Description In order to get from one of the F (1 <= F <= 5,000) grazing fields ...

  5. POJ3177:Redundant Paths(并查集+桥)

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19316   Accepted: 8003 ...

  6. 缩点【洛谷P2860】 [USACO06JAN]冗余路径Redundant Paths

    P2860 [USACO06JAN]冗余路径Redundant Paths 为了从F(1≤F≤5000)个草场中的一个走到另一个,贝茜和她的同伴们有时不得不路过一些她们讨厌的可怕的树.奶牛们已经厌倦了 ...

  7. POJ 3177 Redundant Paths(边双连通的构造)

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13717   Accepted: 5824 ...

  8. [双连通分量] POJ 3177 Redundant Paths

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13712   Accepted: 5821 ...

  9. tarjan算法求桥双连通分量 POJ 3177 Redundant Paths

    POJ 3177 Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12598   Accept ...

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

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

随机推荐

  1. 外文翻译 《How we decide》赛场上的四分卫

    本书导言翻译 为了能看懂这一章,先做了如下的功课: 百度百科 四分卫 国家橄榄球联盟中文站 在2002年超级碗赛场上,比赛的时间仅剩80秒,两队比分持平.新英格兰爱国者队于17码的位置执球,他们的对手 ...

  2. spark on yarn模式下内存资源管理(笔记1)

    问题:1. spark中yarn集群资源管理器,container资源容器与集群各节点node,spark应用(application),spark作业(job),阶段(stage),任务(task) ...

  3. scala如何在任意方法中打印当前线程栈信息(StackTrace)

    1.以wordcount为例 package org.apache.spark.examples import org.apache.spark.{SparkConf, SparkContext} / ...

  4. iTOP-4412开发板网盘资料介绍

    iTOP-4412开发板网盘视频资料内容如下: 01-烧写.编译以及基础知识视频 02-嵌入式Linux 视频 03-iTOP-4412 开发板硬件设计指导视频 04-Android 应用程序视频 0 ...

  5. Locations for Public Frameworks

    Locations for Public Frameworks Third-party frameworks can go in a number of different file-system l ...

  6. 【原创】webbluetoorh 在windows下无法显示搜索列表,在mac下正常的解决办法

    google webbluetooth在windows下不能弹出设备搜索列表提示“Web Bluetooth API is not available”,因为webbluetooth是google新推 ...

  7. IDEA常见问题

    IDEA常见问提解决 一:拉取git代码认证失败(无法重新输入账户和密码) git config --system --unset credential.helper   二:取消新建文件自动添加到S ...

  8. 微信小程序---账号注册与开发工具

    (1)申请帐号 进入小程序注册页 根据指引填写信息和提交相应的资料,就可以拥有自己的小程序帐号. 在这个小程序管理平台,你可以管理你的小程序的权限,查看数据报表,发布小程序等操作. 登录 小程序后台  ...

  9. 为什么 [\000-\177]匹配任意7bit ascii码 ?

    如题 41     print \000;     42     print "\n";     43     print \177; 输出: SCALAR(0x3fce0)SCA ...

  10. PHP 下基于 php-amqp 扩展的 RabbitMQ 简单用例 (二) -- Topic Exchange 和 Fanout Exchange

    Topic Exchange 此模式下交换机,在推送消息时, 会根据消息的主题词和队列的主题词决定将消息推送到哪个队列. 交换机只会为 Queue 分发符合其指定的主题的消息. 向交换机发送消息时,消 ...