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中View游戏开发框架
java中游戏开发引擎View比较适合被动触发的游戏,不能使用于那种对战的游戏 Game01Activity.java 这里是调用的activity package cn.sun.syspro; i ...
- 导出你的GAC Assembly中的DLLS
方法1: CMD命令中,进入C:\windows\assembly,然后XCOPY GAC_MSIL c:\temp /E 这样就得到了dlls了,以命名空间来分类. 如果想将dlls从集合中分出来, ...
- Getting Started with Testing ——开始单元测试
Android tests are based on JUnit, and you can run them either as local unit tests on the JVM or as i ...
- 用layer添加UIView的动画
项目有时会遇到用UIView 添加动画的情况,这里我觉得在layer上添加动画比较好,因为可以详细地设定动画属性,方便理解 下面是一个旋转动画: -(void)roundBtnAction:(id)s ...
- mysql数据库容量查询
1.统计每张表的数据量SELECT *FROM ( select TABLE_NAME, concat( round( sum(DATA_LENGTH / 1024 / 1024 ), 7 ) ) a ...
- 在O(1)时间删除链表结点
//给定单向链表的头指针和一个结点指针,定义一个函数在O(1)时间删除该结点. 1 struct ListNode //结点结构 { int m_nValue; ListNode* m_pNext; ...
- 【POJ2352】【树状数组】Stars
Description Astronomers often examine star maps where stars are represented by points on a plane and ...
- java dos下中文乱码
代码如下: public class PrintString{ public static void main(String args[]){ System.out.println("\\* ...
- php开发利器
phpstorm 当前版本2016.1 之前用的为Zend studio,比之notepad++确实方便很多,不过很多方面还是不方便的,比如定位文件,上传下载到svn什么的. 看到phpstorm新版 ...
- Flask 富文本编辑器
XHEditor http://segmentfault.com/blog/digwtx/1190000002439076 CKeditor http://segmentfault.com/blog/ ...