POJ 1144 Network(割点)
Description
Input
Output
题目大意:给一个n个点的无向连通图,求删掉一个点后,可以使图不连通的点数。
思路:裸的求割点题。
代码(16MS):
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; const int MAXN = ;
const int MAXE = MAXN * MAXN; int head[MAXN], ecnt;
int to[MAXE], next[MAXE];
int pre[MAXN], lowlink[MAXN], dfs_clock;
bool iscut[MAXN];
int n, m, ans; void init() {
memset(head, , sizeof(head));
memset(pre, , sizeof(pre));
memset(iscut, , sizeof(iscut));
ecnt = ;
ans = dfs_clock = ;
} void add_edge(int u, int v) {
to[ecnt] = v; next[ecnt] = head[u]; head[u] = ecnt++;
to[ecnt] = u; next[ecnt] = head[v]; head[v] = ecnt++;
//printf("%d--%d\n", u, v);
} void dfs(int fa, int u) {
pre[u] = lowlink[u] = ++dfs_clock;
int child = ;
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
if(v == fa) continue;
if(!pre[v]) {
++child;
dfs(u, v);
lowlink[u] = min(lowlink[u], lowlink[v]);
if(pre[u] <= lowlink[v]) iscut[u] = true;
} else lowlink[u] = min(lowlink[u], pre[v]);
}
if(fa < && child == ) iscut[u] = false;
} char s[ * MAXN], *p, *prev; int get_int(char *&src) {
while(!isdigit(*src) && *src) ++src;
int ret = ;
while(isdigit(*src)) ret = ret * + *src++ - '';
return ret;
} int main() {
while(scanf("%d", &n) != EOF && n) {
init();
int u, v;
while(gets(s) && *s != '') {
p = s;
u = get_int(p);
while((v = get_int(p)) > ) add_edge(u, v);
}
dfs(-, );
for(int i = ; i <= n; ++i) ans += iscut[i];
printf("%d\n", ans);
}
}
POJ 1144 Network(割点)的更多相关文章
- poj 1144 Network(割点)
题目链接: http://poj.org/problem?id=1144 思路分析:该问题要求求出无向联通图中的割点数目,使用Tarjan算法即可求出无向联通图中的所有的割点,算法复杂度为O(|V| ...
- poj 1144 Network(割点 入门)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10907 Accepted: 5042 Descript ...
- POJ 1144 Network(无向图连通分量求割点)
题目地址:id=1144">POJ 1144 求割点.推断一个点是否是割点有两种推断情况: 假设u为割点,当且仅当满足以下的1条 1.假设u为树根,那么u必须有多于1棵子树 2.假设u ...
- POJ 1144 Network(Tarjan求割点)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12707 Accepted: 5835 Descript ...
- poj 1144 Network 图的割顶判断模板
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8797 Accepted: 4116 Descripti ...
- poj 1144 Network(无向图求割顶数)
题目链接:poj 1144 题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数. 直接上大白书上的 ...
- poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】
题目地址:http://poj.org/problem?id=1144 题目:输入一个n,代表有n个节点(如果n==0就结束程序运行). 在当下n的这一组数据,可能会有若干行数据,每行先输入一个节点a ...
- poj 1144 Network【双连通分量求割点总数】
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11042 Accepted: 5100 Descript ...
- POJ 1144 Network(tarjan 求割点个数)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17016 Accepted: 7635 Descript ...
- poj 1144 Network 无向图求割点
Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...
随机推荐
- 表达式过滤器currency
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- 构建高可靠hadoop集群之2-机栈
本文主要参考 http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-common/RackAwareness.html had ...
- Keepalived搭建主从架构、主主架构实例
实例拓扑图: DR1和DR2部署Keepalived和lvs作主从架构或主主架构,RS1和RS2部署nginx搭建web站点. 注意:各节点的时间需要同步(ntpdate ntp1.aliyun.co ...
- VMware下CentOS7安装后,还原虚拟网络后,敲ifconfig不显示局域网ip解决方法
VMware下CentOS7安装后,还原虚拟网络后,敲ifconfig不显示局域网ip,没有出现eth0网卡,不能上网,SSH不能连接,输入ifconfig后如下图: 解决方法: 1.编辑网卡的配置文 ...
- css3新样式
超出两行变省略号 overflow:hidden; text-overflow:ellipsis;display:-webkit-box; -webkit-box-orient:vertical;-w ...
- Python Web开发中,WSGI协议的作用和实现原理详解
首先理解下面三个概念: WSGI:全称是Web Server Gateway Interface,WSGI不是服务器,python模块,框架,API或者任何软件,只是一种规范,描述web server ...
- 20145202马超 2016-2017-2 《Java程序设计》第一次实验
之前做的(http://www.cnblogs.com/tuolemi/p/5707098.html) 其余的 断点的使用 行断点 条件断点 参考(http://www.cnblogs.com/roc ...
- EAS_Table
SHR人力 员工表 T_BD_PERSON fbirthday 出生日期 femployeetypeid 员工状态 员工状态 T_HR_BDEMPLOYEETYPE T ...
- P1103 书本整理
P1103 书本整理 题目描述 Frank是一个非常喜爱整洁的人.他有一大堆书和一个书架,想要把书放在书架上.书架可以放下所有的书,所以Frank首先将书按高度顺序排列在书架上.但是Frank发现,由 ...
- C++基础语言知识大汇总(不断更新!!!)
经过十天的时间,LITTLESUN做好了前期的工作,今天LITTLESUN就要在新地图里扬帆起航喽!!!(撒花) 简单的整理了一下这次启航准备好的物资.后面的航程中也会不断来补充这个小仓库哦!