Description:

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

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

  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4. const int N = 1e4 + ;
  5.  
  6. int head[N], now = ;
  7. struct edges{
  8. int to, next;
  9. }edge[N<<];
  10. void add(int u, int v){ edge[++now] = {v, head[u]}; head[u] = now;}
  11.  
  12. int n, m, dfn[N], cnt, tot, bri[N<<], vis[N], low[N], dict[N], num, deg[N];
  13. struct input{
  14. int x, y;
  15. }in[N];
  16.  
  17. void tarjan(int x, int in_edge){
  18. dfn[x] = low[x] = ++cnt;
  19. for(int i = head[x]; i; i = edge[i].next){
  20. int v = edge[i].to;
  21. if(!dfn[v]){
  22. tarjan(v, i);
  23. low[x] = min(low[x], low[v]);
  24. if(low[v] > dfn[x]) bri[i] = bri[i ^ ] = ;
  25. }
  26. else if(i != (in_edge ^ )) low[x] = min(low[x], dfn[v]);
  27. }
  28. }
  29.  
  30. void dfs(int x){
  31. dict[x] = tot; vis[x] = ;
  32. for(int i = head[x]; i; i = edge[i].next){
  33. int v = edge[i].to;
  34. if(vis[v] || bri[i]) continue;
  35. dfs(v);
  36. }
  37. }
  38. int main(){
  39. ios::sync_with_stdio(false);
  40. cin>>n>>m;
  41. int x, y;
  42. for(int i = ; i <= m; i++){
  43. cin>>x>>y;
  44. in[i] = {x, y};
  45. add(x, y); add(y, x);
  46. }
  47. for(int i = ; i <= n; i++)
  48. if(!dfn[i]) tarjan(i, );
  49. for(int i = ; i <= n; i++)
  50. if(!vis[i]) tot++, dfs(i);
  51. for(int i = ; i <= m; i++){
  52. if(dict[in[i].x] == dict[in[i].y]) continue;
  53. deg[dict[in[i].x]]++, deg[dict[in[i].y]]++;
  54. }
  55. for(int i = ; i <= tot; i++)
  56. if(deg[i] == ) num++;
  57. cout<<(num + ) / << endl;
  58. return ;
  59. }

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. 用libevent实现的echo服务器及telnet客户端

    以下代码在vs 2010编译通过,使用的libevent版本是:libevent-2.0.22,win7环境测试通过. 服务器实现: 1 流程图: 2 代码: // my_telnet.cpp : D ...

  2. 理解glance

    摘要: 本节介绍 OpenStack Image 服务 Glance 的基本概念. OpenStack 由 Glance 提供 Image 服务. 理解 Image 要理解 Image Service ...

  3. iis 10 重新注册iis

    iis 10 使用该命令 提示 版本不支持 C:\WINDOWS\system32>c:\windows\microsoft.net\framework64\v4.0.30319\aspnet_ ...

  4. pxe+kickstart无人值守安装

    常用软件安装及使用目录 第1章 以前是怎么安装系统的 l 光盘(ISO文件,光盘的镜像文件)===>每一台物理机都得给一个光驱,如果用外置光驱的话,是不是每台机器都需要插一下 l U盘:ISO镜 ...

  5. POJ 2986 A Triangle and a Circle(三角形和圆形求交)

    Description Given one triangle and one circle in the plane. Your task is to calculate the common are ...

  6. Java学习个人备忘录之关键字static

    被static标记的东西会放在内存中被共享的,对象用到时,就会来取的. class Person { String name; //成员变量,实例变量 static String country = ...

  7. Hadoop 版本 生态圈 MapReduce模型

    忘的差不多了, 先补概念, 然后开始搭建集群实战 ... . 一 Hadoop版本 和 生态圈 1. Hadoop版本 (1) Apache Hadoop版本介绍 Apache的开源项目开发流程 : ...

  8. LintCode-365.二进制中有多少个1

    二进制中有多少个1 计算在一个 32 位的整数的二进制表式中有多少个 1. 样例 给定 32 (100000),返回 1 给定 5 (101),返回 2 给定 1023 (111111111),返回 ...

  9. Kafka Streams演示程序

    本文从以下六个方面详细介绍Kafka Streams的演示程序: Step 1: 下载代码 Step 2: 启动kafka服务 Step 3: 准备输入topic并启动Kafka生产者 Step 4: ...

  10. 抽象类 C#

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...