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 ...
随机推荐
- 用libevent实现的echo服务器及telnet客户端
以下代码在vs 2010编译通过,使用的libevent版本是:libevent-2.0.22,win7环境测试通过. 服务器实现: 1 流程图: 2 代码: // my_telnet.cpp : D ...
- 理解glance
摘要: 本节介绍 OpenStack Image 服务 Glance 的基本概念. OpenStack 由 Glance 提供 Image 服务. 理解 Image 要理解 Image Service ...
- iis 10 重新注册iis
iis 10 使用该命令 提示 版本不支持 C:\WINDOWS\system32>c:\windows\microsoft.net\framework64\v4.0.30319\aspnet_ ...
- pxe+kickstart无人值守安装
常用软件安装及使用目录 第1章 以前是怎么安装系统的 l 光盘(ISO文件,光盘的镜像文件)===>每一台物理机都得给一个光驱,如果用外置光驱的话,是不是每台机器都需要插一下 l U盘:ISO镜 ...
- 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 ...
- Java学习个人备忘录之关键字static
被static标记的东西会放在内存中被共享的,对象用到时,就会来取的. class Person { String name; //成员变量,实例变量 static String country = ...
- Hadoop 版本 生态圈 MapReduce模型
忘的差不多了, 先补概念, 然后开始搭建集群实战 ... . 一 Hadoop版本 和 生态圈 1. Hadoop版本 (1) Apache Hadoop版本介绍 Apache的开源项目开发流程 : ...
- LintCode-365.二进制中有多少个1
二进制中有多少个1 计算在一个 32 位的整数的二进制表式中有多少个 1. 样例 给定 32 (100000),返回 1 给定 5 (101),返回 2 给定 1023 (111111111),返回 ...
- Kafka Streams演示程序
本文从以下六个方面详细介绍Kafka Streams的演示程序: Step 1: 下载代码 Step 2: 启动kafka服务 Step 3: 准备输入topic并启动Kafka生产者 Step 4: ...
- 抽象类 C#
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...