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 ...
随机推荐
- OSG-HUD
本文转至http://www.cnblogs.com/shapherd/archive/2010/08/10/osg.html 作者写的比较好,再次收藏,希望更多的人可以看到这个文章 互联网是是一个相 ...
- mysql面试常见题目3
三十六大 冯唐 春水初生, 春林初盛, 春风十里,不如你. 秋风落叶, 秋雨绵绵, 愁心上秋,只为你. 某个员工信息表结构和数据如下: id name dept salary edlevel hire ...
- Android intel X86 图像渲染
最近几天有个项目需要在intel 芯片的系统上集成我们的视频通话软件.之前只是在ARM平台上使用,对于intel 没测试过,直接运行apk后,本端渲染的图像出错,渲染出的图像很像I420被作为RGB5 ...
- 第一章 了解TCP/IP协议族
第一章 了解TCP/IP协议族 1.1 TCP/IP协议族体系结构以及主要协议 IP和TCP协议对编写程序具有最直接的影响,后面的章节会详细的讲到. TCP/IP的体系结构有应用层,传输层,网络层,数 ...
- JDK源码分析:Short.java
Short是基本数据类型short的包装类. 1)声明部: public final class Short extends Number implements Comparable<Short ...
- dotnetframe的清理工具
微软的产品一向不敢恭维,卸载都没有办法卸载干净,卸载又慢又不彻底,dotnet被我卸载之后还有注册表残留以至于无法重新安装. .NET Framework Cleanup Tool真的很好用,全部版本 ...
- 90 [LeetCode] Subsets2
Given a collection of integers that might contain duplicates, nums, return all possible subsets (the ...
- Ubuntu16.04安装truffle时的一些错误
1.使用truffle时出现 Error: /usr/bin/env: node: 没有那个文件或目录 1.如果是用sudo apt-get install nodejs命令安装的nodejs, ub ...
- python函数中的位置参数、默认参数、关键字参数、可变参数区别
一.位置参数 调用函数时根据函数定义的参数位置来传递参数. #!/usr/bin/env python # coding=utf-8 def print_hello(name, sex): sex_d ...
- SGU 194 Reactor Cooling(无源无汇上下界可行流)
Description The terrorist group leaded by a well known international terrorist Ben Bladen is bulidin ...