<题目链接>

题目大意:

给出一个无向图,求出其中的割点数量。

解题分析:

无向图求割点模板题。

一个顶点u是割点,当且仅当满足
(1) u为树根,且u有多于一个子树。
(2) u不为树根,且满足存在(u,v)为树枝边(或称 父子边,即u为v在搜索树中的父亲),使得 dfn(u)<=low(v)。(也就是说V没办法绕过 u 点到达比 u dfn要小的点)
注:这里所说的树是指,DFS下的搜索树。
 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int M =1e4+;
int dfn[M],low[M],father[M],head[M];
int n,m,tot,top,cnt;
struct EDGE{
int to,next;
}edge[M];
void init(){
memset(head,-,sizeof(head));
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(father,,sizeof(father));
tot=cnt=;
}
void add(int u,int v){
edge[++cnt].to=v,edge[cnt].next=head[u];
head[u]=cnt;
}
void Targan(int u,int fa){
dfn[u]=low[u]=++tot;
father[u]=fa; //记录每个节点的父亲
for(int i=head[u];~i;i=edge[i].next){
int v=edge[i].to;
if(!dfn[v]){
Targan(v,u);
low[u]=min(low[u],low[v]);
}
else if(fa!=v){
low[u]=min(dfn[v],low[u]);
}
}
}
void solve(){
int rootson=,ans=;
bool cut[M]={false}; //标记该点是否为割点
Targan(,-); //从1开始遍历整张图
for(int i=;i<=n;i++){
int u=father[i];
if(u==)rootson++; //父亲为根节点,则根节点的分支+1
else if(dfn[u]<=low[i])cut[u]=true; //说明i无法绕过它的父亲节点到达比dfn[u]更小的节点,说明u为割点
}
for(int i=;i<=n;i++){
if(cut[i])ans++;
}
if(rootson>)ans++; //如果根节点的子树数>1,则说明该根节点是割点
printf("%d\n",ans);
}
int main(){
while(scanf("%d",&n)!=EOF,n){
init();
int u,v;
char ch;
while(scanf("%d",&u),u){
while(scanf("%d%c",&v,&ch)){
add(u,v),add(v,u);
if(ch=='\n')break;
}
}
solve();
}
}
 
 
 
2018-10-17

UVA 315 Network (模板题)(无向图求割点)的更多相关文章

  1. (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. (连通图 模板题 无向图求桥)Critical Links -- UVA -- 796

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. uva 315 Network(无向图求割点)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. 无向图求割点 UVA 315 Network

    输入数据处理正确其余的就是套强联通的模板了 #include <iostream> #include <cstdlib> #include <cstdio> #in ...

  5. UVA - 315 Network(tarjan求割点的个数)

    题目链接:https://vjudge.net/contest/67418#problem/B 题意:给一个无向连通图,求出割点的数量.首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第 ...

  6. B - Network---UVA 315(无向图求割点)

        A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connectin ...

  7. poj 1144 Network 无向图求割点

    Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...

  8. Uva 315 Network 判断割点

    模板题,注意输出 #include <stdio.h> #include <string.h> #include <algorithm> #include < ...

  9. 连通分量模板:tarjan: 求割点 &amp;&amp; 桥 &amp;&amp; 缩点 &amp;&amp; 强连通分量 &amp;&amp; 双连通分量 &amp;&amp; LCA(近期公共祖先)

    PS:摘自一不知名的来自大神. 1.割点:若删掉某点后.原连通图分裂为多个子图.则称该点为割点. 2.割点集合:在一个无向连通图中,假设有一个顶点集合,删除这个顶点集合,以及这个集合中全部顶点相关联的 ...

随机推荐

  1. UserNotifications ios10 通知使用

    通知在ios10 中推荐使用 导入  import UserNotifications  头文件 if #available(iOS 10.0, *) { UNUserNotificationCent ...

  2. html超文本标记语言

     <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  3. ionic3 出现莫名广告

    应用上线出现 有莫名其妙的广告弹出. 1,DNS被劫持 2,第三方包带广告 3,Http被劫持 wifi和4G网都出现了广告,所以可以直接排除DNS被劫持的问题 广告页只会在H5的页面出现,所以基本可 ...

  4. hdu4003

    /*依赖背包的通常做法就是对于每个结点,先处理处其所有子节点的dp,然后对于当前结点进行分组背包dp即可 还是依赖背包问题,dp[i][j]表示结点i的子树用了j个机器人的搜索代价 边界条件,如果某个 ...

  5. postMan测试https接口

    一.如何安装postman? Postman下载地址https://www.getpostman.com/ 我下载的版本是Postman-win64-5.0.0-Setup.exe 这是免安装的,可以 ...

  6. 批量杀掉多个pid文件中记录的pid进程, 并集成到shell脚本中

    head_files=`find ./fmsConf/ -name "*.pid"` for file in $head_files do cat $file | awk rm - ...

  7. Windows文件系统

    微软在Dos/Windows系列操作系统中共使用了6种不同的文件系统(包括即将在windows的下一个版本中使用的Winfs).它们分别是:FAt12.FAT16.FAT32.NTFS.NTFS5.0 ...

  8. SCSS 使用@each 方法循环遍历数组颜色并给li赋值

    $list-bg:red,orange,blue,skyblue; ul{ >li{ height: 30px; @each $c in $list-bg{ $i:index($list-bg, ...

  9. bootstrap-table 刷新页面数据

    bom.bootstrapTable('load',msg['object']);//这一步 务必要添加. if(msg['code']==1){ bom.find('tbody').css('dis ...

  10. windows server 2012 R2 远程桌面授权模式尚未配置

    windows server 2012 R2 远程桌面授权模式尚未配置,远程桌面服务将在120天内停止工作.如何破解这个宽限期,目前企业7位协议号码均不包含2012 R2以上授权. 那么只能蛋疼的“破 ...