题目地址:http://poj.org/problem?id=1144

题目:输入一个n,代表有n个节点(如果n==0就结束程序运行)。

在当下n的这一组数据,可能会有若干行数据,每行先输入一个节点a, 接下来先输入一个字符,再输入一个数b,

表示a与b是连通的,如果输入的字符是空格就继续本行的输入,如果是'\n',就结束本行的输入。(可以看本题目

最后的提示部分)

建完图后就是进行tarjan的dfs算法了,是割点的标记一下,割边就不用管了。

code:

#include <iostream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <utility>
#include <vector>
#include <algorithm>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <string.h>
#include <string>
#define N 1010 using namespace std; //邻接矩阵实现 求割边 割点
int n;
bool g[N][N];
bool vis[N];
int dfn[N], low[N], parent[N];
bool cut_point[N]; //是不是割点 void tarjan(int u)
{
static int counter=0;
int children=0;
vis[u]=true; dfn[u]=low[u]=++counter; for(int k=1; k<=n; k++){
if(g[u][k]==true){
int v=k; if(!vis[v]){
children++;
parent[v]=u;
tarjan(v);
low[u]=min(low[u], low[v]);
if(parent[u]== -1 && children >1){
cut_point[u]=true;
}
if(parent[u]!= -1 && low[v]>=dfn[u] ){
cut_point[u]=true;
}
if(low[v]>dfn[u]){
//这是割边
}
}
else if(v!=parent[u]){
low[u]=min(low[u], dfn[v]);
}
}
}
} int main()
{
int i, j;
while(scanf("%d", &n)&&n!=0 ){
int a, b;
memset(g, false, sizeof(g));
memset(vis, false, sizeof(vis));
memset(parent, -1, sizeof(parent));
memset(cut_point, false, sizeof(cut_point)); while(scanf("%d", &a) && a!=0 ){
while(getchar()!='\n'){
scanf("%d", &b);
g[a][b]=true; g[b][a]=true;//建立双向边
}
} tarjan(1);
int cnt=0;
for(i=1; i<=n; i++){
if(cut_point[i]==true ){
cnt++;
}
}
printf("%d\n", cnt ); }
return 0;
}

poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】的更多相关文章

  1. POJ 1144 Network(Tarjan求割点)

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

  2. HDU-1695 GCD(求一个区间内与一个数互质的个数)

    题意: 给你一个T,是样例的个数,接下来是五个数l1,r1,l2,r2,k  前四个数代表两个区间(l1,r1),(l2,r2)这个题l1=1,l2=1; 取x1属于(1,r1),x2属于(1,r2) ...

  3. 求一个数组的最大k个数(java)

    问题描写叙述:求一个数组的最大k个数.如,{1,5,8,9,11,2,3}的最大三个数应该是,8,9,11 问题分析: 1.解法一:最直观的做法是将数组从大到小排序,然后选出当中最大的K个数.可是这种 ...

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

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

  5. [poj 1144]Network[Tarjan求割点]

    题意: 求一个图的割点. 输入略特别: 先输入图中点的总数, 接下来每一行首先给出一个点u, 之后给出一系列与这个点相连的点(个数不定). 行数也不定, 用0作为终止. 这样的输入还是要保证以数字读入 ...

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

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

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

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

  8. POJ 1144 Network【割顶】

    学习的这一篇:https://www.byvoid.com/blog/biconnect 割顶:对于无向图G,如果删除某个点u后,连通分量数目增加,称u为图的关节点或者割顶 u为割顶的条件: (1)u ...

  9. PIGS POJ - 1149网络流(最短增广路---广搜) + 建图

    题意: 第一行输入m和n,m是猪圈的数量,n是顾客的数量,下面n行 第 i+1行表示第i个顾客 , 输入第一个数字表示有几把猪圈的钥匙,后面输入对应的猪圈,最后一个数字输入顾客想买几头猪. 建图: 设 ...

随机推荐

  1. Write operations are not allowed in read-only mode (FlushMode.MANUAL)

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述 搭建SSH框架后,为测试事务配置是否生效,因此在事务配置中取消了保存方法,然后再保存方法中手动抛出异常(已测试配置事务后没有保存成功), ...

  2. linux中查找文件并合并文件

    find ./src -name '*.txt' -exec cat '{}' \; > test.txt

  3. FILE 创建

    public class CreateDelFileUtils implements Serializable{ /** * */ private static final long serialVe ...

  4. Educational Codeforces Round 27 F. Guards In The Storehouse

    F. Guards In The Storehouse time limit per test 1.5 seconds memory limit per test 512 megabytes inpu ...

  5. Swift开发图解入门

    <论语·卫灵公>有一段经典对白:『子贡问为仁.子曰:工欲善其事,必先利其器. --』. 对于一个程序猿来说,好的工具不意味着一定能产生优质的代码.可是好的工具对提升开发效率的作用还是不言而 ...

  6. CentOS VSCode调试go语言出现:exec: "gcc": executable file not found in PATH

    CentOS VSCode调试go语言出现:exec: "gcc": executable file not found in PATH 解决方案: 执行如下命令安装GCC,然后重 ...

  7. 关于JQ checkbox选择的问题

    今天做了一个狠坑爹的事情. $("#dele_chk").bind('click',function(){ if($(this).attr('checked')){ $(" ...

  8. Linux2_小技巧

    0 鼠标不灵么: 左侧设置图标----显示----未知显示屏--关闭 1 左侧自动隐藏 右键---更改桌面背景---行为--隐藏 2 终端打开 搜索到终端添加到左侧 ctrl+alt+T快捷打开 ct ...

  9. IP地址、子网掩码、网关的关系

    网络管理中的IP地址.子网掩码和网关是每个网管必须要掌握的基础知识,只有掌握它,才能够真正理解TCP/IP协议的设置.以下我们就来深入浅出地讲解什么是子网掩码. IP地址的结构 要想理解什么是子网掩码 ...

  10. linux下nginx安装php

    把php安装包上传到linux的/usr/local/src 1.解压 cd /usr/local/src tar zxvf php-5.6.9.tar.gz cd php-5.6.9 2.编译安装 ...