poj3177
来源:互联网 发布:淘宝拖鞋批发 编辑:程序博客网 时间:2024/06/05 06:21
Description
Given a description 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
Sample Input
7 71 22 33 42 54 55 65 7
Sample Output
2
Hint
One visualization of the paths is:
1 2 3 +---+---+ | | | | 6 +---+---+ 4 / 5 / / 7 +Building new paths from 1 to 6 and from 4 to 7 satisfies the conditions.
1 2 3 +---+---+ : | | : | | 6 +---+---+ 4 / 5 : / : / : 7 + - - - -Check some of the routes:
1 – 2: 1 –> 2 and 1 –> 6 –> 5 –> 2
1 – 4: 1 –> 2 –> 3 –> 4 and 1 –> 6 –> 5 –> 4
3 – 7: 3 –> 4 –> 7 and 3 –> 2 –> 5 –> 7
Every pair of fields is, in fact, connected by two routes.
It's possible that adding some other path will also solve the problem (like one from 6 to 7). Adding two paths, however, is the minimum.
题意:
为了保护放牧环境,避免牲畜过度啃咬同一个地方的草皮,牧场主决定利用不断迁移牲畜进行喂养的方法去保护牧草。然而牲畜在迁移过程中也会啃食路上的牧草,所以如果每次迁移都用同一条道路,那么该条道路同样会被啃咬过度而遭受破坏。
现在牧场主拥有F个农场,已知这些农场至少有一条路径连接起来(不一定是直接相连),但从某些农场去另外一些农场,至少有一条路可通行。为了保护道路上的牧草,农场主希望再建造若干条道路,使得每次迁移牲畜时,至少有2种迁移途径,避免重复走上次迁移的道路。已知当前有的R条道路,问农场主至少要新建造几条道路,才能满足要求?
代码:
var
a:array [1..5000,1..500] of longint;
i,j,m,n,x,y,d,q,ans,t,p,leaf:longint;
low,dfn,c,st,bcc:array [1..5000] of longint;
b:array [1..10000,1..2] of longint;
ff,k:array [1..5000,1..5000] of boolean;
f:array [1..5000] of boolean;
function min(x,y:longint):longint;
begin
if x<y then
exit(x);
exit(y);
end;
procedure cut(x,y:longint);
begin
if not k[x,y] then
begin
ff[y,x]:=false;
ff[x,y]:=false;
inc(t);
b[t,1]:=x;
b[t,2]:=y;
end;
end;
procedure find(x,y:longint);
var
i,v,xx:longint;
begin
inc(d);
low[y]:=d;
dfn[y]:=d;
f[y]:=true;
for i:=1 to c[y] do
if (x<>a[y,i]) then
begin
v:=a[y,i];
if not f[v] then
begin
find(y,v);
if low[v]=dfn[v] then
cut(y,v);
low[y]:=min(low[y],low[v]);
end
else
low[y]:=min(low[y],dfn[v]);
end;
end;
procedure dfs(x:longint);
var
i:longint;
begin
f[x]:=true;
bcc[x]:=p;
for i:=1 to c[x] do
if ff[x,a[x,i]] and not f[a[x,i]] then
dfs(a[x,i]);
end;
begin
readln(m,n);
for i:=1 to n do
begin
readln(x,y);
inc(c[x]);
inc(c[y]);
a[x,c[x]]:=y;
a[y,c[y]]:=x;
if ff[x,y] then
begin
k[x,y]:=true;
k[y,x]:=true;
end;
ff[x,y]:=true;
ff[y,x]:=true;
end;
d:=0;
for i:=1 to m do
if not f[i] then
find(-1,i);
fillchar(f,sizeof(f),false);
for i:=1 to m do
if not f[i] then
begin
inc(p);
dfs(i);
end;
fillchar(a,sizeof(a),0);
fillchar(c,sizeof(c),0);
fillchar(ff,sizeof(ff),false);
for i:=1 to t do
begin
x:=b[i,1];
y:=b[i,2];
inc(c[bcc[x]]);
inc(c[bcc[y]]);
end;
for i:=1 to p do
if c[i]=1 then
inc(leaf);
writeln((leaf+1) div 2);
end.
- poj3177
- poj3177
- POJ3177
- POJ3177题解
- POJ 3352 || POJ3177
- poj3177 - Redundant Paths
- POJ3177--Redundant Paths
- 【POJ3177】Redundant Paths
- poj3177 Redundant Paths
- poj3177 双连通分量
- poj3177 Redundant Paths
- POJ3177 Redundant Paths
- POJ3177 Redundant Paths
- 【poj3177】 Redundant Paths
- poj3177 Redundant Paths
- Redundant Paths(POJ3177)
- POJ3177【边双连通分量缩点】
- poj3177-tarjan求桥/割边
- Hdu 2795-Billboard【线段树 优化】
- 00-自测3. 数组元素循环右移问题 (20)
- 数据表如何加索引和一些sql写法注意项
- Chrome 中的 JavaScript 断点设置和调试技巧
- 【iOS】TableView的footerView不随cell滚动而停留在tableView底部的问题
- poj3177
- Android中 ScrollView(ListView)中嵌套ListView时显示不全的简便解决方案
- PCI总线协议(一)
- 利用UICollectionView 实现 页面瀑布流效果
- 利用栈Stack实现队列(Queue)
- iOS开发UI篇—Button基础
- RMQ-区间最值问题
- Volley框架个人心得体会
- 可重入和不可重入的概念