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.割点集合:在一个无向连通图中,假设有一个顶点集合,删除这个顶点集合,以及这个集合中全部顶点相关联的 ...
随机推荐
- Mysql哪些字段适合建立索引
数据库建立索引常用的规则如下: 1.表的主键.外键必须有索引: 2.数据量超过300的表应该有索引: 3.经常与其他表进行连接的表,在连接字段上应该建立索引: 4.经常出现在Where子句中的字段,特 ...
- 【mysql】datetime时间比较
如下,比较的日期用指定格式写出就可以了.不需要日期函数. SELECT * FROM table_a WHERE write_date > "2017-07-17 00:00:00&q ...
- 【splunk】按时间统计并找到异常值
场景: 有长时间对多个端口访问的日志数据,每天对端口的访问量是稳定的.如果某一天对某个端口的访问量突然增加表示可能出现了问题.现在要通过splunk找到异常值. 思路: 统计每个端口每天的访问量.统计 ...
- bzoj 5418
这是拓展crt的典型应用 在你开始做之前,我一定要告诉你一件事情:虽然这道题看着和拓展crt模板很像,但他俩是有巨大的区别的!不要直接把板子改吧改吧扔上去! 题目模型:求解模线性方程组 其中p1,p2 ...
- 右键菜单添加打开CMD选项
转载: https://www.cnblogs.com/mkdd/p/8649139.html#undefined 目前用的win7sp1系统,平时打开CMD窗口通常用三种方法:1.win+R然后输入 ...
- jQuery示例
<!DOCTYPE html><html lang="en" class="loading"><head> <meta ...
- Python推荐系统库--Surprise理论
Surprise Surprise是scikit系列中的一个.Surprise的User Guide有详细的解释和说明 支持多种推荐算法 基础算法/baseline algorithms 基于近邻方法 ...
- python 内建函数
# # __geratteibute__class Itcast(object): def __init__(self,subject1): self.subject1 = subject1 self ...
- 数组练习题A财务管理
第一次看全英文的题,还是有点不舒服的感觉,还是用了翻译器 Larry graduated this year and finally has a job. He's making a lot of m ...
- .Net(C#)用正则表达式清除HTML标签(包括script和style),保留纯本文(UEdit中编写的内容上传到数据库)
去官网下载,本Demo用的MVC模式 下载地址:http://ueditor.baidu.com/website/download.html 加入文件夹中的结构: 引入了函数公式的图标: @{ Vie ...