边双连通有一个非常简单的做法就是先找出所有桥,然后再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. 标准C++中string类的用法

    转自博客园:http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html 相信使用过MFC编程的朋友对CString这个类的印象应该非 ...

  2. OpenJudge 2786 Pell数列

    1.链接地址: http://bailian.openjudge.cn/practice/2786 2.题目: 总Time Limit: 3000ms Memory Limit: 65536kB De ...

  3. OpenJudge 2773 2726 2727 采药

    1.链接地址: http://bailian.openjudge.cn/practice/2773/ http://bailian.openjudge.cn/practice/2726/ http:/ ...

  4. ThinkPHP3.2 加载过程(三)

    上次回顾: IS_CGI ,IS_WIN,IS_CLI,MAGIC_QUOTES_GPC干嘛用 IS_WIN 看了一下后面的代码  基本上就是为了保证在不同环境下运行时,由于有些操作系统会对文件路径大 ...

  5. RX学习笔记:FreeCodeCamp的JavaScript基本算法挑战

    FreeCodeCamp的JavaScript基本算法挑战 https://www.freecodecamp.com 2016-07-03 JavaScript还不是非常熟悉,用已经会的知识来解这些题 ...

  6. 大话F#和C#:是否会重蹈C#失败的覆辙?

    F#.net 出来有些年头儿了,将从 VS 2010 起在 .net framework 平台上以“一等公民”身份粉墨登场的它,将会给计算机科技与软件工业带来哪些悲喜剧呢? F# 将扮演一个什么角色? ...

  7. C语言的数据类型

    复习之余,做点笔记<C语言之数据类型> 一.整数数据类型 (1)整数数据类型 整数类型 char 字符型变量   1字节(8Bit) short 短整型      2字节(16Bit) i ...

  8. entity framework extended library , bulk execute,deleting and updating ,opensource

    http://weblogs.asp.net/pwelter34/entity-framework-batch-update-and-future-queries

  9. Event Aggregator

    /** * Created with JetBrains WebStorm. * User: 宇乔 * Date: 13-8-2 * Time: 下午3:01 * To change this tem ...

  10. 黄聪:如何使用CodeSmith批量生成代码(转:http://www.cnblogs.com/huangcong/archive/2010/06/14/1758201.html)

    先看看CodeSmith的工作原理: 简单的说:CodeSmith首先会去数据库获取数据库的结构,如各个表的名称,表的字段,表间的关系等等,之后再根据用户自定义好的模板文件,用数据库结构中的关键字替代 ...