题目链接: http://poj.org/problem?id=1144

思路分析:该问题要求求出无向联通图中的割点数目,使用Tarjan算法即可求出无向联通图中的所有的割点,算法复杂度为O(|V| + |E|);

代码如下:

#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
using namespace std; const int MAX_N = + ;
const int MAX_M = + ;
char str[MAX_M];
vector<int> G[MAX_N];
int pre[MAX_N], is_cut[MAX_N], low[MAX_N];
int dfs_clock; inline int Min(int a, int b) { return a < b ? a : b; }
int Dfs(int u, int fa)
{
int lowu = pre[u] = ++dfs_clock;
int child = ; for (int i = ; i < G[u].size(); ++i)
{
int v = G[u][i];
if (!pre[v])
{
child++;
int lowv = Dfs(v, u);
lowu = Min(lowu, lowv);
if (lowv >= pre[u])
is_cut[u] = true;
} else if (pre[v] < pre[u] && v != fa)
lowu = Min(lowu, pre[v]);
}
if (fa < && child == )
is_cut[u] = ;
low[u] = lowu;
return lowu;
} int main()
{
int ver_num; while (scanf("%d", &ver_num) != EOF && ver_num)
{
getchar( );
int ver_start, ver_next; memset(pre, , sizeof(pre));
memset(low, , sizeof(low));
memset(is_cut, , sizeof(is_cut));
for (int i = ; i < MAX_N; ++i)
G[i].clear( );
while (scanf("%d", &ver_start) && ver_start)
{
while (getchar() != '\n')
{
scanf("%d", &ver_next);
G[ver_start].push_back(ver_next);
G[ver_next].push_back(ver_start);
}
}
int cut_ver_count = ;
dfs_clock = ;
Dfs(, -);
for (int i = ; i <= ver_num; ++i)
{
if (is_cut[i])
cut_ver_count++;
}
printf("%d\n", cut_ver_count);
}
return ;
}

poj 1144 Network(割点)的更多相关文章

  1. poj 1144 Network(割点 入门)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10907   Accepted: 5042 Descript ...

  2. POJ 1144 Network(无向图连通分量求割点)

    题目地址:id=1144">POJ 1144 求割点.推断一个点是否是割点有两种推断情况: 假设u为割点,当且仅当满足以下的1条 1.假设u为树根,那么u必须有多于1棵子树 2.假设u ...

  3. POJ 1144 Network(Tarjan求割点)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12707   Accepted: 5835 Descript ...

  4. poj 1144 Network 图的割顶判断模板

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8797   Accepted: 4116 Descripti ...

  5. poj 1144 Network(无向图求割顶数)

    题目链接:poj 1144 题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数. 直接上大白书上的 ...

  6. poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】

    题目地址:http://poj.org/problem?id=1144 题目:输入一个n,代表有n个节点(如果n==0就结束程序运行). 在当下n的这一组数据,可能会有若干行数据,每行先输入一个节点a ...

  7. poj 1144 Network【双连通分量求割点总数】

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11042   Accepted: 5100 Descript ...

  8. POJ 1144 Network(tarjan 求割点个数)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17016   Accepted: 7635 Descript ...

  9. poj 1144 Network 无向图求割点

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

随机推荐

  1. powerdesigener 12.5注册机

    下载链接 下载链接 密码:awg9

  2. php以fastCGI的方式运行在iis下,遇到的文件系统权限问题及解决方法

    今天准备将一个php demo放在IIS下运行,网站在IIS下的配置是这样的: 应用程序池是集成模式下的.net framework 2.0(2.0或4.0没什么关系,因为php以fastCGI的方式 ...

  3. ffmpeg用法

    1. help ffmpeg.exe -h > help.txt 2. 解码: ffmpeg -i 123.264 123.yuv ffmpeg -i 123.264 -vframes 200  ...

  4. SublimeLinter

    SublimeLinter 关于代码检查 郑重推荐这个插件 官方插件库中仅有sublime3 有此插件 (对于ST2 有个sublimeLinter for ST2 没试过) SublimeLinte ...

  5. Spring-AOP实践

    Spring-AOP实践 公司的项目有的页面超级慢,20s以上,不知道用户会不会疯掉,于是老大说这个页面要性能优化.于是,首先就要搞清楚究竟是哪一步耗时太多. 我采用spring aop来统计各个阶段 ...

  6. java核心技术学习笔记之三程序设计结构

    一 基本数据结构 必须包括在类中 必须具备 public static main方法 大小写敏感 二.数据类型 四种整数类型: Int 4字节 short 2字节 long8字节 byte1字节 二种 ...

  7. 6_StopWatch

    6 // // ViewController.swift // StopWatch // // Created by ZC on 16/1/9. // Copyright © 2016年 ZC. Al ...

  8. CFBundleName系列参数的含义

    顺带讲一下其他这些选项表示什么意思: CFBundleName: CFBundleName指定了该束的简称.简称应该小于16个字符并且适合在菜单和“关于”中显示.通过把它加入到适当的.lproj子文件 ...

  9. ubuntu12.04下 安装虚拟主机

    Ubuntu Linux 方法一 一.修改/etc/apache2/sites-available/ 1. 打开目录 /etc/apache2/sites-available/, 发现 default ...

  10. maven项目启动

    1服务install 2 build (tomcat:run)