POJ 3177 Redundant Paths(重边标记法,有重边的边双连通分支)
大致题意:
为了保护放牧环境,避免牲畜过度啃咬同一个地方的草皮,牧场主决定利用不断迁移牲畜进行喂养的方法去保护牧草。然而牲畜在迁移过程中也会啃食路上的牧草,所以如果每次迁移都用同一条道路,那么该条道路同样会被啃咬过度而遭受破坏。
现在牧场主拥有F个农场,已知这些农场至少有一条路径连接起来(不一定是直接相连),但从某些农场去另外一些农场,至少有一条路可通行。为了保护道路上的牧草,农场主希望再建造若干条道路,使得每次迁移牲畜时,至少有2种迁移途径,避免重复走上次迁移的道路。已知当前有的R条道路,问农场主至少要新建造几条道路,才能满足要求?


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <cstring>
usingnamespace std;
#define INF 0xfffffff
#define maxn 10025
#define min(a,b) (a<b?a:b)
int m, n, Time, cnt, top;
int dfn[maxn], block[maxn], low[maxn], Father[maxn], Stack[maxn];
vector<int> G[maxn];
void init()
{
memset(dfn, , sizeof(dfn));
memset(low, , sizeof(low));
memset(block, , sizeof(block));
memset(Father, , sizeof(Father));
top = Time = cnt = ; for(int i=; i<=n; i++)
G[i].clear();
}
void Tarjan(int u,int fa)
{
dfn[u] = low[u] = ++Time;
Father[u] = fa;
Stack[top++] = u;
int len = G[u].size(), v, k = ; for(int i=; i<len; i++)
{
v = G[u][i];
if(v == fa && !k)
{
k ++;
continue;
} if(!low[v])
{
Tarjan(v, u);
low[u] = min(low[u], low[v]);
}
else
low[u] = min(low[u], dfn[v]);
} if(dfn[u] == low[u])
{
do
{
v = Stack[--top];
block[v] = cnt;
}while(u != v);
cnt ++;
}
} void solve()
{
int i, degree[maxn] = {}, ans = ;
for(i=; i<=n; i++)
{
if( !low[i] )
Tarjan(i, i);
} for(i=; i<=n; i++)
{
int v = Father[i];
if(block[i] != block[v])
{
degree[block[i] ] ++;
degree[block[v] ] ++;
}
} for(i=; i<cnt; i++)
{
if(degree[i] == )
ans ++;
}
printf("%d\n", (ans+)/ );
} int main()
{
while(scanf("%d %d",&n, &m) != EOF)
{
init();
while(m --)
{
int a, b;
scanf("%d %d",&a, &b);
G[a].push_back(b);
G[b].push_back(a);
}
solve();
}
return0;
}


POJ 3177 Redundant Paths(重边标记法,有重边的边双连通分支)的更多相关文章
- tarjan算法求桥双连通分量 POJ 3177 Redundant Paths
POJ 3177 Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12598 Accept ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
- POJ 3177 Redundant Paths(边双连通的构造)
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13717 Accepted: 5824 ...
- POJ 3177——Redundant Paths——————【加边形成边双连通图】
Redundant Paths Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- POJ 3177 Redundant Paths & POJ 3352 Road Construction(双连通分量)
Description In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numb ...
- [双连通分量] POJ 3177 Redundant Paths
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13712 Accepted: 5821 ...
- poj 3177 Redundant Paths
题目链接:http://poj.org/problem?id=3177 边双连通问题,与点双连通还是有区别的!!! 题意是给你一个图(本来是连通的),问你需要加多少边,使任意两点间,都有两条边不重复的 ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction
这两题是一样的,代码完全一样. 就是给了一个连通图,问加多少条边可以变成边双连通. 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话,把双连通子图收缩为一个点,形成一颗树 ...
- poj 3177 Redundant Paths【求最少添加多少条边可以使图变成双连通图】【缩点后求入度为1的点个数】
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11047 Accepted: 4725 ...
- POJ - 3177 Redundant Paths(边双连通分支)(模板)
1.给定一个连通的无向图G,至少要添加几条边,才能使其变为双连通图. 2. 3. //边双连通分支 /* 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话, 把双连通子图 ...
随机推荐
- JAVA 原始国际化例子
import java.text.MessageFormat; import java.util.Locale; import java.util.ResourceBundle; public cla ...
- Java——(一)一切都是对象
------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- 一.用引用操纵对象 在java中一切都被视为对象,但操纵的标识符实际上是对象的一个“引用”( ...
- springmvc xml 空模板
<?xml version="1.0" encoding="UTF-8"?><!-- Bean头部 --><beans xmlns ...
- 关键词:CodeSmith工具、Money类型、__UNKNOWN__
问题描述: 当数据库列类型有Money类型的时候,CodeSmith生成数据访问层会出错.有不能识别的类型.解决方法: 通过查找资料得知,数据库中的Money类型在DbType中是Currency(货 ...
- ASP.NET Excel数据导入数据库
<identity impersonate="true"/> 是指模拟IIS身份验证 導入錯誤時可刪除 protected void btnImport_Click(o ...
- CentOS下的svn强制用户提交时写日志
问题:在项目提交时候不写日志,在后期查看修改历史时需要对比版本才知道提交原因.解决方案:在svn服务端通过hooks在提交时强制要求写日志.#!/bin/shREPOS="$1"T ...
- iOS 百度地图监听地图状态
百度地图提供了地图状态的对象BMKMapStatus ///此类表示地图状态信息 @interface BMKMapStatus : NSObject { float _fLevel; // 缩放比例 ...
- php输出echo、print、print_r、printf、sprintf、var_dump的区别比较
本篇文章是对php输出echo.print.print_r.printf.sprintf.var_dump的区别进行了详细的分析介绍,需要的朋友参考下 用.net开发已经5年了,最近突然想接触 ...
- 向RichTextBox控件不停的AppendText数据时,如何把光标的焦点始终显示到最后
上面是csdn上的一个网友的问题,我的一个实现如下://让文本框获取焦点this.richTextBoxInfo.Focus();//设置光标的位置到文本尾this.richTextBoxInfo.S ...
- 找出整数中第k大的数
一 问题描述: 找出 m 个整数中第 k(0<k<m+1)大的整数. 二 举例: 假设有 12 个整数:data[1, 4, -1, -4, 9, 8, 0, 3, -8, 11, 2 ...