【POJ1144】Network(割点)(模板)
题意:给定一张无向图,求割点个数
思路:感谢CC大神http://ccenjoyyourlife.blog.163.com/的讲解
割点的定义就是某个联通块中删去此点连通性发生变化的的点
有两种割点:1.U为树根,子树个数>1
2.U非树根,有U的子节点V满足low[v]>=dfn[u]表示U的V子树必须通过U去到U的上面
更新时也有两种:dfn[u]<dfn[v]时u--->v 实边 反则u--->v 虚边
实边时low[u]=min(low[u],low[v]) 虚边low[u]=min(low[u],dfn[v])
var head,vet,next,low,dfn,b,son,flag:array[..]of longint;
n,m,x,i,tot,time,ans:longint; procedure add(a,b:longint);
begin
inc(tot);
next[tot]:=head[a];
vet[tot]:=b;
head[a]:=tot;
end; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; procedure dfs(u:longint);
var e,v:longint;
begin
flag[u]:=;
inc(time); low[u]:=time; dfn[u]:=time;
e:=head[u];
while e<> do
begin
v:=vet[e];
if flag[v]= then
begin
inc(son[u]);
dfs(v);
low[u]:=min(low[u],low[v]);
if (low[v]>=dfn[u])and(u<>) then b[u]:=;
end
else low[u]:=min(low[u],dfn[v]);
e:=next[e];
end;
end; begin
assign(input,'1.in'); reset(input);
assign(output,'1.out'); rewrite(output);
repeat
readln(n);
if n= then break;
fillchar(head,sizeof(head),);
fillchar(low,sizeof(low),);
fillchar(dfn,sizeof(dfn),);
fillchar(flag,sizeof(flag),);
fillchar(son,sizeof(son),);
fillchar(b,sizeof(b),);
repeat
read(m);
while not eoln do
begin
read(x);
add(x,m);
add(m,x);
end;
until m=;
time:=;
for i:= to n do
if flag[i]= then dfs(i);
ans:=;
for i:= to n do if b[i]= then inc(ans);
if son[]> then inc(ans);
writeln(ans);
until n=;
close(input);
close(output);
end.
【POJ1144】Network(割点)(模板)的更多相关文章
- [poj1144]Network(求割点模板)
解题关键:割点模板题. #include<cstdio> #include<cstring> #include<vector> #include<stack& ...
- POJ1144 Network(割点)题解
Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are c ...
- UVA 315 Network (模板题)(无向图求割点)
<题目链接> 题目大意: 给出一个无向图,求出其中的割点数量. 解题分析: 无向图求割点模板题. 一个顶点u是割点,当且仅当满足 (1) u为树根,且u有多于一个子树. (2) u不为树根 ...
- HDU4738 tarjan割边|割边、割点模板
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4738 坑点: 处理重边 图可能不连通,要输出0 若求出的结果是0,则要输出1,因为最少要派一个人 #inc ...
- Tarjan求强连通分量、求桥和割点模板
Tarjan 求强连通分量模板.参考博客 #include<stdio.h> #include<stack> #include<algorithm> using n ...
- poj1144 Network【tarjan求割点】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4319585.html ---by 墨染之樱花 [题目链接]http://poj.org/p ...
- POJ1144:Network(无向连通图求割点)
题目:http://poj.org/problem?id=1144 求割点.判断一个点是否是割点有两种判断情况: 如果u为割点,当且仅当满足下面的1条 1.如果u为树根,那么u必须有多于1棵子树 2. ...
- 求割点模板(可求出割点数目及每个割点分割几个区域)POJ1966(Cable TV Network)
题目链接:传送门 题目大意:给你一副无向图,求解图的顶点连通度 题目思路:模板(图论算法理论,实现及应用 P396) Menger定理:无向图G的顶点连通度k(G)和顶点间最大独立轨数目之间存在如下关 ...
- POJ1144 Network 无向图割点
题目大意:求以无向图割点. 定义:在一个连通图中,如果把点v去掉,该连通图便分成了几个部分,则v是该连通图的割点. 求法:如果v是割点,如果u不是根节点,则u后接的边中存在割边(u,v),或者v-&g ...
- POJ1144 Network 题解 点双连通分量(求割点数量)
题目链接:http://poj.org/problem?id=1144 题目大意:给以一个无向图,求割点数量. 这道题目的输入和我们一般见到的不太一样. 它首先输入 \(N\)(\(\lt 100\) ...
随机推荐
- java基础—GUI编程(二)
一.事件监听
- python-判断alter是否存在
from selenium import webdriver import time from selenium.webdriver.support.ui import WebDriverWait f ...
- sql*plus常用指令介紹
sql*plus常用指令介紹 1.用set指令來設定SQL*Plus的環境參數值 格式: Set 環境參數名 環境參數值 ex:set feedback on set feedback 8.用show ...
- 配置淘宝镜像,不使用怪异的cnpm
npm config set registry https://registry.npm.taobao.org --global npm config set disturl https://npm. ...
- 字节跳动后端开发实习生面试(Python)
一面: 1.自我介绍. 2.介绍“工大小美”项目相关. 3.Python中的GIL(全局解释器锁),以及哪种情况下使用python的多线程性能有较大的提升. 4.项目中用到了SQLite数据库,如果有 ...
- Python学习笔记:PyInstaller(exe程序打包)
PyInstaller可以将Python程序打包成一个exe程序来独立运行,用户使用时只需要执行这个exe文件即可,不需要在机器上再安装Python及其他包就可运行了.另外,PyInstaller相较 ...
- hdu-1338 game predictions(贪心题)
Suppose there are M people, including you, playing a special card game. At the beginning, each playe ...
- phpMyAdmin关于PHP 5.5+ is required. Currently installed version is: 5.4.16问题
出现这个提示PHP 5.5+ is required. Currently installed version is: 5.4.16原因可能是: phpmyadmin 版本太新,最小需要php5.5. ...
- navigationcontroller和navigationbar和navigationitem之间的区别以及不用nib实现点击屏幕关闭虚拟键盘20130911
1.UIViewController UIView的关系. UIView是视图,UIViewController是视图控制器,两者之间是从属关系,当创建一个UIViewController的时候,一般 ...
- bootstrap里的fileimput的小问题
fileinput 是bootstrap 里面一个非常好的插件 于是我很开心的开始的使用了 $("#file_upload").fileinput({ uploadUrl: &qu ...