边双连通有一个非常简单的做法就是先找出所有桥,然后再dfs一次不走桥即可
答案是(叶子节点的个数+1)/2

 type node=record
next,po:longint;
end; var e:array[..] of node;
p,dfn,low,d,be,fa:array[..] of longint;
hash:array[..,..] of boolean;
b:array[..] of boolean;
len,n,m,x,y,i,ans,t,s,j,h,r:longint; function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end; procedure add(x,y:longint);
begin
hash[x,y]:=true;
inc(len);
e[len].po:=y;
e[len].next:=p[x];
p[x]:=len;
end; procedure tarjan(x:longint);
var i,y:longint;
begin
inc(h);
dfn[x]:=h;
low[x]:=h;
i:=p[x];
while i<>- do
begin
y:=e[i].po;
if y<>fa[x] then
begin
if dfn[y]= then
begin
fa[y]:=x;
tarjan(y);
end;
low[x]:=min(low[x],low[y]);
if low[y]>dfn[x] then
begin
b[i]:=true;
b[i xor ]:=true;
end;
end;
i:=e[i].next;
end;
end; procedure dfs(x:longint);
var i,y:longint;
begin
be[x]:=s;
i:=p[x];
while i<>- do
begin
y:=e[i].po;
if (be[y]=) and not b[i] then dfs(y);
if b[i] and (be[x]<>be[y]) then inc(d[be[x]]);
i:=e[i].next;
end;
end; begin
len:=-;
fillchar(p,sizeof(p),);
readln(n,m);
for i:= to m do
begin
readln(x,y);
if not hash[x,y] then
begin
add(x,y);
add(y,x);
end;
end;
tarjan();
for i:= to n do
if be[i]= then
begin
inc(s);
dfs(i);
end; for i:= to s do
if d[i]= then inc(ans);
writeln((ans+) shr );
end.

poj3177的更多相关文章

  1. POJ3177 & 求边双联通分量

    题意: 给一张无向图,求加多少边使原图任意两点边双联通. SOL: 一个不会写边双点双强联通的傻逼. 一个结论:把一棵树变成满足条件的图需要加的边使入度为1的点数+1除以2.------>就是树 ...

  2. 【poj3177】 Redundant Paths

    http://poj.org/problem?id=3177 (题目链接) 题意 给出一个n个节点m条边的无向图,求最少连几条边使图中没有桥. Solution 我们可以发现,用最少的边使得图中没有桥 ...

  3. POJ3177(3352)(边双连通分量)

    题目: 原本没有记录桥是谁,而是染色时即时判断的.后来发现不行,因为a去b可能满足low[b]>dfn[a],但b去a就不满足了. 这是因为low和dfn的关系是相对的,仅限于tarjan时的那 ...

  4. poj3177 && poj3352 边双连通分量缩点

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12676   Accepted: 5368 ...

  5. [POJ3177]Redundant Paths(双联通)

    在看了春晚小彩旗的E技能(旋转)后就一直在lol……额抽点时间撸一题吧…… Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Tota ...

  6. POJ3177 Redundant Paths(边双连通分量+缩点)

    题目大概是给一个无向连通图,问最少加几条边,使图的任意两点都至少有两条边不重复路径. 如果一个图是边双连通图,即不存在割边,那么任何两个点都满足至少有两条边不重复路径,因为假设有重复边那这条边一定就是 ...

  7. [POJ3177]Redundant Paths(双连通图,割边,桥,重边)

    题目链接:http://poj.org/problem?id=3177 和上一题一样,只是有重边. 如何解决重边的问题? 1.  构造图G时把重边也考虑进来,然后在划分边双连通分量时先把桥删去,再划分 ...

  8. poj3177 Redundant Paths

    Description In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numb ...

  9. poj3177(边双连通分量+缩点)

    传送门:Redundant Paths 题意:有n个牧场,Bessie 要从一个牧场到另一个牧场,要求至少要有2条独立的路可以走.现已有m条路,求至少要新建多少条路,使得任何两个牧场之间至少有两条独立 ...

随机推荐

  1. (转)TCP注册端口号大全

    分类: 网络与安全 cisco-sccp 2000/tcp Cisco SCCPcisco-sccp 2000/udp Cisco SCCp# Dan Wing <dwing&cisco ...

  2. nodejs连接MySQL数据库

    在github上搜索orm2 https://github.com/dresende/node-orm2: 在项目文件夹使用npm install orm下载下来,然后书写配置文件 var orm = ...

  3. 暑假集训(3)第三弹 -----Til the Cows Come Home(Poj2387)

    题意梗概:据说母牛在产奶的时候,因为奶量太充足,希望有人帮它挤奶,它回家就很快.我们便能喝到鲜美的 牛奶,不过,贫奶季节却大不相同,它会懒洋洋的在大草原上晃来晃去的晒太阳,而不会想到马上回家,这可不 ...

  4. cocos2dx 初探 - VS2012 HELLOWORLD

    最近决定用cocos2dx 来做些试验性的东西,先装了个vs2012 再从网上下了cocos2dx-2.1.4就开工了. 仅是Windows 桌面调试还是很简单的. 上面三个项目源: Hellocpp ...

  5. 在LaTeX中利用preview宏包和tikz宏包生成单图pdf

    有时候我们利用tikz宏包画出的图片后,只想生成一个单图pdf,而且pdf的页面大小与图片相同,以便于以后再次用latex插入. 可以与preview宏包进行搭配,页面大小由图像大小决定,可以通过改变 ...

  6. 代C语言上机实践

    这已经是开学第十二周了,个人感觉严老师教的这批学生效果不是很好,有的竟然毫不知道main函数前边的 int是做什么的.只知按照书本上给的样例程序一个字一个字的敲到编译器中,然后点击运行.有错误也不知道 ...

  7. .Net 中资源的使用方式

    近期要在小丸工具箱中添加一个启动画面,画面中需要使用一个GIF动图.经过学习和实验,总结了几个读取资源的方式,罗列如下. 一.使用外部资源 Image img = Image.FromFile(&qu ...

  8. C# 实体model验证输出

    新建Model实体: [Required(ErrorMessage = @"地址 1 为必填项!")] [StringLength(, ErrorMessage = @" ...

  9. 用php生成word文档

    一.用windows里面自带的com,然后用php生成word文档 <?php $word= new COM("word.application") or die(" ...

  10. Linux下18b20温度传感器驱动代码及测试实例

    驱动代码: #include <linux/module.h> #include <linux/fs.h> #include <linux/kernel.h> #i ...