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.割点集合:在一个无向连通图中,假设有一个顶点集合,删除这个顶点集合,以及这个集合中全部顶点相关联的 ...
随机推荐
- 关于 IOS 时间的一下用法
1. 加减月份 -(NSDate *)getPriousorLaterDateFromDate:(NSDate *)date withMonth:(int)month { NSDateComp ...
- System.TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception. ---> Oracle.DataAccess.Client.OracleException: 提供程序与此版本的 Oracle 客户机不兼容”
.net应用程序通过Oracle.DataAccess.dll访问64位的Oracle服务器,在连接时出现以下异常:“System.TypeInitializationException: The t ...
- JS实现图片放大查看
示例:https://wumaozheng.com/static-pages/image-magnifier.html <!DOCTYPE html> <html> <h ...
- ios蓝牙详解
最近这段时间在研究蓝牙,也研究了一段时间了现在在下面做个总结 1 其实蓝牙连接只要明白了整体原理,其实挺简单的 2 大部分情况下,手机作为中心管理者,而连接的设备被称为外设,外设的结构有点像一颗大树 ...
- ubuntu MySQL的安装
https://i.cnblogs.com/EditPosts.aspx?opt=1 https://juejin.im/entry/5adb5deff265da0b9d77cb3b MySQL Co ...
- The import util cannot be resolved
代码: 明显的错误: 应改成 import java.util.*; 没有理解java的基本概念
- git bash中的快捷键
转载: https://www.cnblogs.com/dhuhewang/p/6504914.html 1.bash命令格式 命令 [-options] [参数],如:tar zxvf dem ...
- 80端口被占用 导致apach无法启动问题
1.查找是哪个程序占用了80端口 netstat -ano 列出所有进程 观察 “本地地址” 列 找到对应的PID 我这里是4 简单的办法,打开任务管理器,查看PID是4的 是哪个进程. 发现是Sys ...
- IDEA新建模块
- Django 基模板布局设置
Django 基模板布局设置 基模板 定义基础模板一般分为三块,css部分,body部分,js部分 将基础统一的部分写在基础模板中 差异部分直接 引用 {% block css %}{% endblo ...