poj3177 BZOJ1718 Redundant Paths
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的更多相关文章
- 【poj3177】 Redundant Paths
http://poj.org/problem?id=3177 (题目链接) 题意 给出一个n个节点m条边的无向图,求最少连几条边使图中没有桥. Solution 我们可以发现,用最少的边使得图中没有桥 ...
- POJ3177:Redundant Paths——题解
http://poj.org/problem?id=3177 明显要求桥的一道题. (因为有桥就说明只能从那一条路走,换句话说就是只有一种方法) 求完桥后按照结论(加几条边成双连通图的结论,不会请ba ...
- [POJ3177]Redundant Paths(双联通)
在看了春晚小彩旗的E技能(旋转)后就一直在lol……额抽点时间撸一题吧…… Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Tota ...
- POJ3177 Redundant Paths 双连通分量
Redundant Paths Description In order to get from one of the F (1 <= F <= 5,000) grazing fields ...
- POJ3177:Redundant Paths(并查集+桥)
Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19316 Accepted: 8003 ...
- 【bzoj1718】Redundant Paths 分离的路径
1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 964 Solve ...
- POJ3177 Redundant Paths —— 边双联通分量 + 缩点
题目链接:http://poj.org/problem?id=3177 Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total ...
- 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: 65536K Total Submissions: 13712 Accepted: 5821 ...
随机推荐
- 【SpringCloud】第六篇: 分布式配置中心(Spring Cloud Config)
前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...
- 第六模块:WEB框架开发 第1章·Django框架开发1~50
01-Django基础介绍 02-Web应用程序1 03-Web应用程序2 04-http请求协议1 05-http请求协议2 06-http协议之响应协议 07-wsgire模块1 08-wsgir ...
- node事件循环
Node.js 是单进程单线程应用程序,但是通过事件和回调支持并发,所以性能非常高. Node.js 的每一个 API 都是异步的,并作为一个独立线程运行,使用异步函数调用,并处理并发. Node.j ...
- RSA算法笔记+理解
明天网络安全考试了,看了一下午,还没理解透,持续更新... 质数: 除了1和它本身以外不再有其他因素的数互质关系: 两个正整数,除了1以外,没有其他公因子RSA实现了非对称加密DES实现了对称加密** ...
- spark操作数据库的几种方法
一.使用jdbcRDD的接口: SparkConf conf = new SparkConf(); conf.setAppName("Simple Application").se ...
- Android开发-API指南-<permission>
<permission> 英文原文:http://developer.android.com/guide/topics/manifest/permission-element.html 采 ...
- 【Linux 运维】 Centos7.x 系统修复模式
一.linux的运行级别: 运行级别就是来确定系统启动时到底启动那个服务. linux默认有7个运行级别: 0 关机 1 单用户模式,用于系统修复 2 不完全的命令模式,不含NFS服务 3 完全的命令 ...
- JQuery常用函数方法全集
Attribute: $("p").addClass(css中定义的样式类型); 给某个元素添加样式 $("img").attr({src:"test ...
- codeforces 301D Yaroslav and Divisors(树状数组)
Yaroslav has an array p = p1, p2, ..., pn (1 ≤ pi ≤ n), consisting of n distinct integers. Also, he ...
- v-if或者v-repeat等不起作用
v-if或者v-for等不起作用 在项目中,有时遇到了v-if或v-for等形式时,页面没起作用.以下可能是出现这些问题的原因: 1.绑定值是接口返回的某个属性值,而这个属性值不存在data()中,这 ...