求割点

一种显然的n^2做法:

  枚举每个点,去掉该点连出的边,然后判断整个图是否联通

用tarjan求割点:

  分情况讨论

  如果是root的话,其为割点当且仅当下方有两棵及以上的子树

  其他情况

  设当前节点为u,一个儿子节点为v

  存在low[v]>=dfn[u],也就是说其儿子节点v能连到的最前面的点都在u的下面

  也就是当u断开的时候,u之前的点与以v为根的子树必然分成两个独立的块

  那么这个时候u就是割点


  

Network

A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The lines are bidirectional and always connect together two places and in each place the lines end in a telephone exchange. There is one telephone exchange in each place. From each place it is 
possible to reach through lines every other place, however it need not be a direct connection, it can go through several exchanges. From time to time the power supply fails at a place and then the exchange does not operate. The officials from TLC realized that in such a case it can happen that besides the fact that the place with the failure is unreachable, this can also cause that some other places cannot connect to each other. In such a case we will say the place (where the failure 
occured) is critical. Now the officials are trying to write a program for finding the number of all such critical places. Help them.

  直接贴模板

program poj1144;
const maxn = ;
var n,e,i,j,x,y,time,ans,u,v:longint;
fa,next,link,low,dfn,hash:array[-..maxn]of longint;
vis:array[-..maxn]of boolean; procedure add(x,y:longint);
begin
inc(e);fa[e]:=y;next[e]:=link[x];link[x]:=e;
inc(e);fa[e]:=x;next[e]:=link[y];link[y]:=e;
end; function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end; procedure tarjan(p:longint);
var j:longint;
begin
inc(time);dfn[p]:=time;low[p]:=time;vis[p]:=false;
j:=link[p];
while j<> do
begin
if vis[fa[j]] then
begin
tarjan(fa[j]);
if low[fa[j]]>=dfn[p] then inc(hash[p]);
low[p]:=min(low[p],low[fa[j]]);
end else low[p]:=min(low[p],dfn[fa[j]]);
j:=next[j];
end;
end; begin
//assign(input,'poj1144.in');reset(input);
readln(n);
while n<> do
begin
fillchar(link,sizeof(link),);
fillchar(hash,sizeof(hash),);
fillchar(next,sizeof(next),);
e:=;
read(u);
while u<> do
begin
while not eoln do
begin
read(v);
add(u,v);
end;
readln;read(u);
end;
readln;
fillchar(vis,sizeof(vis),true);time:=;
for i:= to n do if vis[i] then tarjan(i);
ans:=;
if hash[]> then inc(ans);
for i:= to n do if hash[i]> then inc(ans);
writeln(ans);
readln(n);
end; end.

矿场搭建

煤矿工地可以看成是由隧道连接挖煤点组成的无向图。为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处。于是矿主决定在某些挖煤点设立救援出口,使得无论哪一个挖煤点坍塌之后,其他挖煤点的工人都有一条道路通向救援出口。请写一个程序,用来计算至少需要设置几个救援出口,以及不同最少救援出口的设置方案总数。

  首先对答案有影响的显然只有割点

  然后考虑把所有割点都去掉,剩下的联通块中如果只与一个割点相连

  这个块中就要放一个出口

  最后特判整个图是一个联通块的情况

  

program bzoj2730;
const maxn = ;maxm = ;
var n,e,time,x,y,ans1,ans2,test,root,tot,m,col:int64;
i,j:longint;
fa,next,stack:array[-..maxm]of int64;
vis,cut,used,exi:array[-..maxn]of boolean;
link,dfn,low,hash,opt:array[-..maxn]of int64; function min(a,b:int64):int64;
begin
if a<b then exit(a) else exit(b);
end; procedure add(x,y:int64);
begin
inc(e);fa[e]:=y;next[e]:=link[x];link[x]:=e;
inc(e);fa[e]:=x;next[e]:=link[y];link[y]:=e;
end; procedure tarjan(p:int64);
var j:int64;
begin
inc(time);dfn[p]:=time;low[p]:=time;vis[p]:=false;stack[time]:=p;
j:=link[p];
while j<> do
begin
if vis[fa[j]] then
begin
tarjan(fa[j]);
if low[fa[j]]>=dfn[p] then inc(hash[p]);
low[p]:=min(low[p],low[fa[j]]);
end else low[p]:=min(low[p],dfn[fa[j]]);
j:=next[j];
end;
end; function bfs(s:int64):int64;
var head,tail,x,j:int64;
begin
fillchar(used,sizeof(used),true);
tot:=;head:=;tail:=;opt[]:=s;vis[s]:=false;
while head<>tail do
begin
inc(head);x:=opt[head];j:=link[x];
while j<> do
begin
if (vis[fa[j]])and(not cut[fa[j]]) then
begin
vis[fa[j]]:=false;
inc(tail);opt[tail]:=fa[j];
end else
if (cut[fa[j]])and(used[fa[j]]) then
begin
inc(tot);
used[fa[j]]:=false;
end;
j:=next[j];
end;
end;
exit(tail);
end; begin
//assign(input,'bzoj2730.in');reset(input);
// assign(output,'col.out');rewrite(output);
readln(m);
test:=;
while m<> do
begin
inc(test);
fillchar(next,sizeof(next),);
fillchar(link,sizeof(link),);
fillchar(exi,sizeof(exi),false);
e:=;time:=;n:=;
for i:= to m do
begin
readln(x,y);
if x>n then n:=x;
if y>n then n:=y;
exi[x]:=true;exi[y]:=true;
add(x,y);
end;
fillchar(vis,sizeof(vis),true);
fillchar(hash,sizeof(hash),);
fillchar(cut,sizeof(cut),false);
for i:= to n do if (vis[i])and(exi[i]) then
begin
tarjan(i);
dec(hash[i]);
end;
for i:= to n do if hash[i]> then cut[i]:=true;
ans1:=;ans2:=;col:=;
fillchar(vis,sizeof(vis),true);
for i:= to n do if (not cut[i])and(vis[i])and(exi[i]) then
begin
tot:=;x:=bfs(i);inc(col);
if tot = then
begin
inc(ans1);
ans2:=ans2*x;
end;
end;
if col = then writeln('Case ',test,': ',,' ',n*(n-) >> )
else writeln('Case ',test,': ',ans1,' ',ans2);
readln(m);
end;
end.

[POJ1144][BZOJ2730]tarjan求割点的更多相关文章

  1. poj1144 tarjan求割点

    poj1144 tarjan求割点 额,算法没什么好说的,只是这道题的读入非常恶心. 注意,当前点x是否是割点,与low[x]无关,只和low[son]和dfn[x]有关. 还有,默代码的时候记住分目 ...

  2. UESTC 900 方老师炸弹 --Tarjan求割点及删点后连通分量数

    Tarjan算法. 1.若u为根,且度大于1,则为割点 2.若u不为根,如果low[v]>=dfn[u],则u为割点(出现重边时可能导致等号,要判重边) 3.若low[v]>dfn[u], ...

  3. POJ 1144 Network(Tarjan求割点)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12707   Accepted: 5835 Descript ...

  4. poj 1523 SPF(tarjan求割点)

    本文出自   http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...

  5. poj_1144Network(tarjan求割点)

    poj_1144Network(tarjan求割点) 标签: tarjan 割点割边模板 题目链接 Network Time Limit: 1000MS Memory Limit: 10000K To ...

  6. 洛谷P3388 【模板】割点(割顶)(tarjan求割点)

    题目背景 割点 题目描述 给出一个n个点,m条边的无向图,求图的割点. 输入输出格式 输入格式: 第一行输入n,m 下面m行每行输入x,y表示x到y有一条边 输出格式: 第一行输出割点个数 第二行按照 ...

  7. tarjan求割点割边的思考

    这个文章的思路是按照这里来的.这里讨论的都是无向图.应该有向图也差不多. 1.如何求割点 首先来看求割点.割点必须满足去掉其以后,图被分割.tarjan算法考虑了两个: 根节点如果有两颗及以上子树,它 ...

  8. Tarjan求割点和桥

    by szTom 前置知识 邻接表存储及遍历图 tarjan求强连通分量 割点 割点的定义 在一个无向图中,如果有一个顶点集合,删除这个顶点集合以及这个集合中所有顶点相关联的边以后,图的连通分量增多, ...

  9. tarjan求割点与割边

    tarjan求割点与割边 洛谷P3388 [模板]割点(割顶) 割点 解题思路: 求割点和割点数量模版,对于(u,v)如果low[v]>=dfn[u]那么u为割点,特判根结点,若根结点子树有超过 ...

随机推荐

  1. 在编程的时候,NotePad++ 中闪烁的光标突然有竖着闪烁的编程蓝色下划线闪烁的--小技巧告诉你-费元星

    当在写代码时出现的光标闪烁(横线闪烁) 在键盘上找 Insert ,按这个Insert就可以把横向闪烁光标( _ )修改成竖向闪烁光标样式( | ),横向光标会在你写代码的时候修改前面的代码,把光标移 ...

  2. mysql ON DUPLICATE KEY UPDATE、REPLACE INTO

    INSERT INTO ON DUPLICATE KEY UPDATE 与 REPLACE INTO,两个命令可以处理重复键值问题,在实际上它之间有什么区别呢?前提条件是这个表必须有一个唯一索引或主键 ...

  3. JDBC剖析篇(1):java中的Class.forName()

    一.Class.forName() 在Java中我们一般用下面这样的语句来连接数据库(以MySQL为例) Class.forName("com.mysql.jdbc.Driver" ...

  4. 线段树简单入门 (含普通线段树, zkw线段树, 主席树)

    线段树简单入门 递归版线段树 线段树的定义 线段树, 顾名思义, 就是每个节点表示一个区间. 线段树通常维护一些区间的值, 例如区间和. 比如, 上图 \([2, 5]\) 区间的和, 为以下区间的和 ...

  5. 『Golang』在Golang中使用json

    由于要开发一个小型的web应用,而web应用大部分都会使用json作为数据传输的格式,所以有了这篇文章. 包引用 import ( "encoding/json" "gi ...

  6. 「日常训练」Mike and Feet(Codeforces Round #305 Div. 2 D)

    题意 (Codeforces 548D) 对一个有$n$个数的数列,我们要求其连续$x(1\le x\le n)$(对于每个$x$,这样的连续group有若干个)的最小数的最大值. 分析 这是一道用了 ...

  7. 菜鸟级appium 必看

    之所以写这个,因为太多新人,appium环境半天都搭建不好,版本问题,兼容问题等等. 自己的解决方案:1 官网下载nodejs,建议安装长期支持版 2 进入appium官网,点击下载,跳转到githu ...

  8. Python 3 学习笔记之——键盘输入和读写文件

    1. 键盘输入 Python提供了 input() 内置函数从标准输入读入一行文本,默认的标准输入是键盘.input 可以接收一个 Python 表达式作为输入,并将运算结果返回. str = inp ...

  9. kaldi学习 - 一脚本流学习工具使用

    目录 yesno训练 先给出整体脚本如下: 分块详解 建立解码脚本 kaldi中脚本东西比较多,一层嵌一层,不易阅读. 本文以yesno为例,直接使用kaldi编译的工具,书写简易训练步骤,方便学习k ...

  10. 简易cmake多文件多目录工程模板

    今天心血来潮,想在服务器上试试写libevent的工程是什么感受,那第一步就是学会怎么用cmake建工程,之前也没接触过cmake,然后一上午,比较懵逼,下午看实验室哥们给的一个教程,然后,慢慢理解C ...