POJ 3177 Redundant Paths & POJ 3352 Road Construction(双连通分量)
Description
Given a descri_ption of the current set of R (F-1 <= R <= 10,000) paths that each connect exactly two different fields, determine the minimum number of new paths (each of which connects exactly two fields) that must be built so that there are at least two separate routes between any pair of fields. Routes are considered separate if they use none of the same paths, even if they visit the same intermediate field along the way.
There might already be more than one paths between the same pair of fields, and you may also build a new path that connects the same fields as some other path.
Input
Lines 2..R+1: Each line contains two space-separated integers which are the fields at the endpoints of some path.
Output
Description
It's almost summer time, and that means that it's almost summer construction time! This year, the good people who are in charge of the roads on the tropical island paradise of Remote Island would like to repair and upgrade the various roads that lead between the various tourist attractions on the island.
The roads themselves are also rather interesting. Due to the strange customs of the island, the roads are arranged so that they never meet at intersections, but rather pass over or under each other using bridges and tunnels. In this way, each road runs between two specific tourist attractions, so that the tourists do not become irreparably lost.
Unfortunately, given the nature of the repairs and upgrades needed on each road, when the construction company works on a particular road, it is unusable in either direction. This could cause a problem if it becomes impossible to travel between two tourist attractions, even if the construction company works on only one road at any particular time.
So, the Road Department of Remote Island has decided to call upon your consulting services to help remedy this problem. It has been decided that new roads will have to be built between the various attractions in such a way that in the final configuration, if any one road is undergoing construction, it would still be possible to travel between any two tourist attractions using the remaining roads. Your task is to find the minimum number of new roads necessary.
Input
The first line of input will consist of positive integers n and r, separated by a space, where 3 ≤ n ≤ 1000 is the number of tourist attractions on the island, and 2 ≤ r ≤ 1000 is the number of roads. The tourist attractions are conveniently labelled from 1 to n. Each of the following r lines will consist of two integers, v andw, separated by a space, indicating that a road exists between the attractions labelled v and w. Note that you may travel in either direction down each road, and any pair of tourist attractions will have at most one road directly between them. Also, you are assured that in the current configuration, it is possible to travel between any two tourist attractions.
Output
One line, consisting of an integer, which gives the minimum number of roads that we need to add.
题目大意:给一个n个点m条边的无向连通图,问最少加上多少条边,可以使这幅图每两点之间都有条以上的路径。
思路:求双连通分量,答案为(度数为1的双连通分量+1)/2。证明略。
PS:由于题目所求的东西导致数据有点水代码正确性未知。
PS2:3177有重边,3352没有重边,我直接拿3177的ACcode砸上3352了。至于重边的问题,个人认为删掉一条是不对的,都能AC只能说明数据水(我删重边AC过,下面的代码是没有删重边的)
代码(3177 0MS / 3352 16MS):
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; const int MAXN = ;
const int MAXE = ; int head[MAXN], sccno[MAXN];
int to[MAXE], next[MAXE];
bool vis[MAXE];
int pre[MAXN], lowlink[MAXN];
int stk[MAXN], top;
int dfs_clock, scc_cnt, ecnt, n, m; void init() {
memset(head, , sizeof(head));
ecnt = ;
} void add_edge(int u, int v) {
to[ecnt] = v; next[ecnt] = head[u]; head[u] = ecnt++;
to[ecnt] = u; next[ecnt] = head[v]; head[v] = ecnt++;
} void dfs(int u) {
pre[u] = lowlink[u] = ++dfs_clock;
stk[top++] = u;
for(int p = head[u]; p; p = next[p]) {
if(vis[p]) continue;
vis[p] = vis[p ^ ] = true;
int &v = to[p];
if(!pre[v]) {
dfs(v);
lowlink[u] = min(lowlink[u], lowlink[v]);
} else lowlink[u] = min(lowlink[u], pre[v]);
}
if(lowlink[u] == pre[u]) {
++scc_cnt;
while(true) {
int x = stk[--top];
sccno[x] = scc_cnt;
if(x == u) break;
}
}
} int deg[MAXN]; int solve() {
for(int i = ; i <= n; ++i)
if(!pre[i]) dfs(i);
int ret = ;
for(int u = ; u <= n; ++u) {
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
if(sccno[u] == sccno[v]) continue;
++deg[sccno[v]];
}
}
for(int i = ; i <= scc_cnt; ++i)
ret += (deg[i] == );
return (ret + ) >> ;
} int main() {
scanf("%d%d", &n, &m);
init();
while(m--) {
int a, b;
scanf("%d%d", &a, &b);
add_edge(a, b);
}
printf("%d\n", solve());
}
POJ 3177 Redundant Paths & POJ 3352 Road Construction(双连通分量)的更多相关文章
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
- POJ 3177 Redundant Paths POJ 3352 Road Construction
这两题是一样的,代码完全一样. 就是给了一个连通图,问加多少条边可以变成边双连通. 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话,把双连通子图收缩为一个点,形成一颗树 ...
- tarjan算法求桥双连通分量 POJ 3177 Redundant Paths
POJ 3177 Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12598 Accept ...
- 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:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- poj 3177 Redundant Paths
题目链接:http://poj.org/problem?id=3177 边双连通问题,与点双连通还是有区别的!!! 题意是给你一个图(本来是连通的),问你需要加多少边,使任意两点间,都有两条边不重复的 ...
- POJ 3177 Redundant Paths (桥,边双连通分量,有重边)
题意:给一个无向图,问需要补多少条边才可以让整个图变成[边双连通图],即任意两个点对之间的一条路径全垮掉,这两个点对仍可以通过其他路径而互通. 思路:POJ 3352的升级版,听说这个图会给重边.先看 ...
- poj 3177 Redundant Paths(边双连通分量+缩点)
链接:http://poj.org/problem?id=3177 题意:有n个牧场,Bessie 要从一个牧场到另一个牧场,要求至少要有2条独立的路可以走.现已有m条路,求至少要新建多少条路,使得任 ...
- POJ 3352 Road Construction 双联通分量 难度:1
http://poj.org/problem?id=3352 有重边的话重边就不被包含在双连通里了 割点不一定连着割边,因为这个图不一定是点连通,所以可能出现反而多增加了双连通分量数的可能 必须要用割 ...
随机推荐
- iOS之UITableView中的cell因为重用机制导致新的cell的数据出现重复或者错乱
UITableView中的cell可以有很多,一般会通过重用cell来达到节省内存的目的:通过为每个cell指定一个重用标识符(reuseIdentifier),即指定了单元格的种类,当cell滚 ...
- Percona-Toolkit工具包之pt-archiver
Preface There's a common case that we neet to archive amount of records in some tables to a ...
- .Net Core On Liunx 环境搭建之 Docker 容器和Nginx
上一篇文章安装了Mysql8数据库,接下开始安装Docker和Nginx 我的思路是这样的,用Docker当运行环境的虚拟机,Nginx当Http服务器用来做反向代理. 服务器环境:阿里云服务器,操作 ...
- 帆软中使用switch将控件的显示值“传递”给单元格
如下图,控件的实际值和显示值是我们自定义的. 当我们选择控件时,想要在某个单元格内显示控件的显示值.一般我们在单元格内直接 $控件名 可以获得控件值.比如当我们选择事故数时,我们自然不能在单元格内直 ...
- 二、Django需要的知识点
1.请求(request): 客户端到服务器端. 响应(response):服务器端到客户端. HTTP/1.1 协议共定义了 8 种请求方式,分别是: OPTIONS. HEAD. GET. POS ...
- BGP(边界网关协议)简述
BGP的起源 不同自治系统(路由域)间路由交换与管理的需求推动了EGP的发展,但是EGP的算法简单,无法选路,从而被BGP取代. 自治系统:(AS) IGP:自治系统内部协议,ospf,rip,is- ...
- 抽象类实验:SIM卡抽象
抽象SIM: package sim_package; public abstract class SIM { public abstract String giveNumber(); public ...
- Java+Selenium3方法篇24-单选和多选按钮操作
Java+Selenium3方法篇24-单选和多选按钮操作 本篇介绍 webdriver处理前端单选按钮的操作.单选按钮一般叫raido button,就像我们在电子版的单选答题过程一样,单选只能点击 ...
- tail命令使用
1.tail命令 命令的主要用途是将指定的文件的最后部分输出到终端,如果该文件有更新,tail会自己主动刷新. 2.tail语法 tail [ -f ] [ -c Number | -n Number ...
- HyperLedger Fabric 1.4 区块链开发平台(4.1)
目前区块链开发平台分“公有链平台”和“联盟链系统”两类,“公有链平台”主要以以太坊为主的平台,可以在该类平台上进行代币的发行和根据各种模块搭建应用:“联盟链系统”主要以超级账本为主的开源系统,该类开源 ...