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. Linux命令应用大词典-第28章 硬件管理

    28.1 lscpu:显示有关CPU架构的信息 28.2 nproc:显示当前进程可用的CPU数目 28.3 chcpu:配置CPU

  2. 【checkbox-group、checkbox】 多项选择器组件说明

    checkbox-group组件包裹checkbox组件的容器 原型: <check-group bindchange="[EventHandle]"> <che ...

  3. JS原型链与继承别再被问倒了

    原文:详解JS原型链与继承 摘自JavaScript高级程序设计: 继承是OO语言中的一个最为人津津乐道的概念.许多OO语言都支持两种继承方式: 接口继承 和 实现继承 .接口继承只继承方法签名,而实 ...

  4. 第三课——MFC编程

    一.MFC概述 1. MFC简述 MFC不仅仅是一套基础类库,更是一种编程方式. 2. MFC由来 1987年微软公司推出了第一代Windows产品,并为应用程序设计者提供了Win16(16位Wind ...

  5. Thunder团队第三周 - Scrum会议2

    Scrum会议2 小组名称:Thunder 项目名称:i阅app Scrum Master:李传康 工作照片: 胡佑蓉在拍照,所以不在照片中. 参会成员: 王航:http://www.cnblogs. ...

  6. python异步初步窥探

    1.异步之难:因为其执行吮吸不可预料,当下正要发生什么事件不可预料.        程序下一步行为往往依赖上一步值执行结果,如何知晓上次异步调用已完成并获取结果,        回调成了必然选择,那又 ...

  7. 2019寒假训练营寒假作业(三) MOOC的网络空间安全概论笔记部分

    目录 第五章 网络攻防技术 5.1:网络信息收集技术--网络踩点 信息收集的必要性及内容 网络信息收集技术 网络踩点(Footprinting) 网络踩点常用手段 5.2:网络信息收集技术 --网络扫 ...

  8. ubuntu 安装 hustoj

    https://github.com/zhblue/hustoj 准备工作: http://www.java123.net/v/961634.html 1.首先打开命令行,切换到root身份,获得最新 ...

  9. 《剑指offer》---输出链表倒数第k个结点

    本文算法使用python3实现 1 题目描述:   输入一个链表,输出该链表中倒数第k个结点.   时间限制:1s:空间限制:32768K 2 思路描述:   方法一:当链表长度为 $ n $ 时,输 ...

  10. C# Winform防止闪频和再次运行

    其实想实现只允许运行一个实例很简单,就是从program的入口函数入手.有两种情况: 第一种,用户运行第二个的时候给一个提示: using System; using System.Collectio ...