Description:

有F个牧场,1<=F<=5000,现在一个牧群经常需要从一个牧场迁移到另一个牧场。奶牛们已经厌烦老是走同一条路,所以有必要再新修几条路,这样它们从一个牧场迁移到另一个牧场时总是可以选择至少两条独立的路。现在F个牧场的任何两个牧场之间已经至少有一条路了,奶牛们需要至少有两条。
给定现有的R条直接连接两个牧场的路,F-1<=R<=10000,计算至少需要新修多少条直接连接两个牧场的路,使得任何两个牧场之间至少有两条独立的路。两条独立的路是指没有公共边的路,但可以经过同一个中间顶点

思路:双联通分量缩点,然后将缩成的树的叶子节点连起来就可以把得到一个双联通图,叶子节点为入度为1的点

#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e4 + ; int head[N], now = ;
struct edges{
int to, next;
}edge[N<<];
void add(int u, int v){ edge[++now] = {v, head[u]}; head[u] = now;} int n, m, dfn[N], cnt, tot, bri[N<<], vis[N], low[N], dict[N], num, deg[N];
struct input{
int x, y;
}in[N]; void tarjan(int x, int in_edge){
dfn[x] = low[x] = ++cnt;
for(int i = head[x]; i; i = edge[i].next){
int v = edge[i].to;
if(!dfn[v]){
tarjan(v, i);
low[x] = min(low[x], low[v]);
if(low[v] > dfn[x]) bri[i] = bri[i ^ ] = ;
}
else if(i != (in_edge ^ )) low[x] = min(low[x], dfn[v]);
}
} void dfs(int x){
dict[x] = tot; vis[x] = ;
for(int i = head[x]; i; i = edge[i].next){
int v = edge[i].to;
if(vis[v] || bri[i]) continue;
dfs(v);
}
}
int main(){
ios::sync_with_stdio(false);
cin>>n>>m;
int x, y;
for(int i = ; i <= m; i++){
cin>>x>>y;
in[i] = {x, y};
add(x, y); add(y, x);
}
for(int i = ; i <= n; i++)
if(!dfn[i]) tarjan(i, );
for(int i = ; i <= n; i++)
if(!vis[i]) tot++, dfs(i);
for(int i = ; i <= m; i++){
if(dict[in[i].x] == dict[in[i].y]) continue;
deg[dict[in[i].x]]++, deg[dict[in[i].y]]++;
}
for(int i = ; i <= tot; i++)
if(deg[i] == ) num++;
cout<<(num + ) / << endl;
return ;
}

poj3177 BZOJ1718 Redundant Paths的更多相关文章

  1. 【poj3177】 Redundant Paths

    http://poj.org/problem?id=3177 (题目链接) 题意 给出一个n个节点m条边的无向图,求最少连几条边使图中没有桥. Solution 我们可以发现,用最少的边使得图中没有桥 ...

  2. POJ3177:Redundant Paths——题解

    http://poj.org/problem?id=3177 明显要求桥的一道题. (因为有桥就说明只能从那一条路走,换句话说就是只有一种方法) 求完桥后按照结论(加几条边成双连通图的结论,不会请ba ...

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

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

  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. 【bzoj1718】Redundant Paths 分离的路径

    1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 964  Solve ...

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

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

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

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

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

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

随机推荐

  1. SSH项目中的困惑之一

    1.request.getContextPath()详解 <%=request.getContextPath()%>是为了解决相对路径的问题,可返回站点的根路径. 但不用也可以,比如< ...

  2. GameplayKit的GKStateMachine用法与实例

    GKStateMachine 玩家进入GameScene场景中 -> 通过GKStateMachine进入到指定的游戏状态GKState 在GameScene场景中 -> 根据不同的逻辑调 ...

  3. lintcode 466. 链表节点计数

    466. 链表节点计数 计算链表中有多少个节点.   样例 给出 1->3->5, 返回 3. /** * Definition of ListNode * class ListNode ...

  4. sql server存储特殊字符解决办法

    好久没来院子了,最近在学java了,再加上项目比较紧,最近都没怎么上,其实这几天在项目中学到不少东西,都能写下来,但是久而久之就忘了,还是得养成及时总结的好习惯啊,还有有时间一定要把那个小项目整理下来 ...

  5. Skype for Business Server 方案

    方案说明: 高可用性的配置屏蔽了单点故障,使得当一个服务器节点失效时,另外的可用的节点能够进行服务的接管.可伸缩性的配置可以保证当即时沟通平台的使用用户增加时,该平台应该具有良好的可伸缩性,能非常方便 ...

  6. “Hello world!”团队—选题展示

    本次选题展示内容: 一.视频展示 链接:http://v.youku.com/v_show/id_XMzA5Mzk5NjYwOA==.html?sharefrom=iphone 视频截图链接:http ...

  7. Java学习个人备忘录之多态

    对象的多态性 class 动物 {} class 猫 extends 动物 {} class 狗 extends 动物 {} 猫 x = new 猫();//意思是建立本类的对象 new 猫(),并通 ...

  8. 从零讲JAVA ,给你一条 清晰地学习道路!该学什么就学什么!!

    1.计算机基础: 1.1数据机构基础: 主要学习:1.向量,链表,栈,队列和堆,词典.熟悉2.树,二叉搜索树.熟悉3.图,有向图,无向图,基本概念4.二叉搜索A,B,C类熟练,9大排序熟悉.5.树的前 ...

  9. 关于PHP使用GD库生成的验证码无法在别处显示

    https://segmentfault.com/q/1010000002522270

  10. 3dContactPointAnnotationTool开发日志(八)

      今天上午去实验室打算把项目从github上pull下来发现貌似不行,然后强行pull下来后项目变得乱七八糟了,有的组件都不知道去哪里了.去github上看了看发现上面day6和day7都没有,特别 ...