UVA 315 Network (模板题)(无向图求割点)
<题目链接>
题目大意:
给出一个无向图,求出其中的割点数量。
解题分析:
无向图求割点模板题。
#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();
}
}
UVA 315 Network (模板题)(无向图求割点)的更多相关文章
- (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- (连通图 模板题 无向图求桥)Critical Links -- UVA -- 796
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- uva 315 Network(无向图求割点)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 无向图求割点 UVA 315 Network
输入数据处理正确其余的就是套强联通的模板了 #include <iostream> #include <cstdlib> #include <cstdio> #in ...
- UVA - 315 Network(tarjan求割点的个数)
题目链接:https://vjudge.net/contest/67418#problem/B 题意:给一个无向连通图,求出割点的数量.首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第 ...
- B - Network---UVA 315(无向图求割点)
A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connectin ...
- poj 1144 Network 无向图求割点
Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...
- Uva 315 Network 判断割点
模板题,注意输出 #include <stdio.h> #include <string.h> #include <algorithm> #include < ...
- 连通分量模板:tarjan: 求割点 && 桥 && 缩点 && 强连通分量 && 双连通分量 && LCA(近期公共祖先)
PS:摘自一不知名的来自大神. 1.割点:若删掉某点后.原连通图分裂为多个子图.则称该点为割点. 2.割点集合:在一个无向连通图中,假设有一个顶点集合,删除这个顶点集合,以及这个集合中全部顶点相关联的 ...
随机推荐
- 软件测试作业 - fault error failure
给出的题目如下: 我的解答如下: For program 1:1. where i > 0 is the fault , it should be changed to i>= 0 to ...
- Java9 新特性 详解
作者:木九天 < Java9 新特性 详解 > Java9 新特性 详解 摘要: 1.目录结构 2.repl工具 jShell命令 3.模块化 4.多版本兼容jar包 5.接口方 ...
- Confluence 6 查看内容索引概要
内容索引,通常也被称为查找索引,这个索引被用来在 Confluence 中支持查找.这个索引同时也被其他的一些功能使用,例如在归档邮件中构建邮件主题,View Space Activity 的特性和将 ...
- Confluence 6 理解你许可证的用户数
基于你的许可证类型,在你 Confluence 可以被注册的用户也许有限制. 在许可证明细页面中,将会告诉当前使用了多少的许可证(你注册的用户数量). 包括仅仅在 Confluence 中可以使用gl ...
- 【python】打印函数调用栈
traceback.print_stack()
- js变量前的+是什么意思
js变量前的+是什么意思 if (+value >= distance) {} 这个+什么意思 可以理解为 Number(value) 会将其按照Number函数的规则转换为数值或者NaN, ...
- Java SimpleDateFormat 中英文时间格式化转换
2015年08月29日 17:37:43 阅读数:32459 SimpleDateFormat是一个以与语言环境有关的方式来格式化和解析日期的具体类.它允许进行格式化(日期 -> 文本).解析( ...
- 论文阅读笔记三十二:YOLOv3: An Incremental Improvement
论文源址:https://pjreddie.com/media/files/papers/YOLOv3.pdf 代码:https://github.com/qqwweee/keras-yolo3 摘要 ...
- Python函数之内置函数
截止导Python 3.6 目前内置函数有68个 以下是对这些内置函数的分类 一:作用域相关 以字典的形式返回作用域中的名字 locals # 返回本地作用域的所有名字 globals # 返回全局作 ...
- HDU 1452 Happy 2004(因数和+费马小定理+积性函数)
Happy 2004 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...