Network
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 11914   Accepted: 5519

Description

A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The lines are bidirectional and always connect together two places and in each place the lines end in a telephone exchange. There is one telephone exchange in each place. From each place it is 
possible to reach through lines every other place, however it need not be a direct connection, it can go through several exchanges. From time to time the power supply fails at a place and then the exchange does not operate. The officials from TLC realized that in such a case it can happen that besides the fact that the place with the failure is unreachable, this can also cause that some other places cannot connect to each other. In such a case we will say the place (where the failure 
occured) is critical. Now the officials are trying to write a program for finding the number of all such critical places. Help them.

Input

The input file consists of several blocks of lines. Each block describes one network. In the first line of each block there is the number of places N < 100. Each of the next at most N lines contains the number of a place followed by the numbers of some places to which there is a direct line from this place. These at most N lines completely describe the network, i.e., each direct connection of two places in the network is contained at least in one row. All numbers in one line are separated 
by one space. Each block ends with a line containing just 0. The last block has only one line with N = 0;

Output

The output contains for each block except the last in the input file one line containing the number of critical places.

Sample Input

5
5 1 2 3 4
0
6
2 1 3
5 4 6 2
0
0

Sample Output

1
2
 
题意:
有n个点,每个点之间都有相连的边。问图中不同的割点有几个。(其实应该是这张图有割点 ,但是割点不是唯一的)
 
思路:
tarjan方法,如果low[t] >= dfn[[rt],说明当前点rt是割点。要注意根节点的判断。
/*
* Author: sweat123
* Created Time: 2016/6/20 21:01:10
* File Name: main.cpp
*/
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<time.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1<<30
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
struct node{
int to;
int next;
}edge[MAXN*MAXN];
int pre[MAXN],vis[MAXN],ind,n,ans;
int dfn[MAXN],low[MAXN];
void add(int x,int y){
edge[ind].to = y;
edge[ind].next = pre[x];
pre[x] = ind ++;
}
void dfs(int rt,int k){
dfn[rt] = k;
low[rt] = k;
for(int i = pre[rt]; i != -; i = edge[i].next){
int t = edge[i].to;
if(!dfn[t]){
dfs(t,k+);
low[rt] = min(low[t],low[rt]);
if(low[t] >= dfn[rt]){
vis[rt] ++;
}
}
else {
low[rt] = min(low[rt],dfn[t]);
}
}
}
int main(){
while(~scanf("%d",&n)){
if(!n)break;
ind = ;
memset(pre,-,sizeof(pre));
while(){
int x,y;
scanf("%d",&x);
if(!x)break;
while(){
scanf("%d",&y);
add(x,y);
add(y,x);
if(getchar() == '\n')break;
}
}
memset(vis,,sizeof(vis));
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
dfs(,);
int ans = ;
vis[] --;
for(int i = ; i <= n; i++){
if(vis[i] > )ans += ;
}
printf("%d\n",ans);
}
return ;
}

poj1144 求不同割点的个数的更多相关文章

  1. poj 1523Tarjan算法的含义——求取割点可以分出的连通分量的个数

    poj 1523Tarjan算法的含义——求取割点可以分出的连通分量的个数 题目大意:如题目所示 给你一些关系图——连通图,想要问你有没有个节点,损坏后,可以生成几个互相独立的网络(也就是连通分量), ...

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

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

  3. UVA - 315 Network(tarjan求割点的个数)

    题目链接:https://vjudge.net/contest/67418#problem/B 题意:给一个无向连通图,求出割点的数量.首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第 ...

  4. tarjan求割边割点

    tarjan求割边割点 内容及代码来自http://m.blog.csdn.net/article/details?id=51984469 割边:在连通图中,删除了连通图的某条边后,图不再连通.这样的 ...

  5. [LeetCode] Count Complete Tree Nodes 求完全二叉树的节点个数

    Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...

  6. 一种快速求fibonacci第n个数的算法

    利用动态规则的思路,摒弃传统的递归做法,可以得到一种快速的求fibonacci第n个数的算法: ''' 求第n(从1开始)位fibonacci数 fibonacci数列前两位为0, 1. 后面每一位数 ...

  7. 【剑指offer】求逆序对的个数

    2013-09-07 10:50:31 面试题36:在数组中的两个数字如果前面一个数字大于后面的数字,则这两个数字构成一个逆序对.输入一个数组,求出这个数组中逆序对的总数. 小结: 最直观的的方法是: ...

  8. 求集合中选一个数与当前值进行位运算的max

    求集合中选一个数与当前值进行位运算的max 这是一个听来的神仙东西. 先确定一下值域把,大概\(2^{16}\),再大点也可以,但是这里就只是写写,所以无所谓啦. 我们先看看如果暴力求怎么做,位运算需 ...

  9. LeetCode 29 Divide Two Integers (不使用乘法,除法,求模计算两个数的除法)

    题目链接: https://leetcode.com/problems/divide-two-integers/?tab=Description   Problem :不使用乘法,除法,求模计算两个数 ...

随机推荐

  1. FMS 客户端带宽计算、带宽限制

    FMS 客户端带宽计算.带宽限制 1. 带宽计算 FMS内置了带宽检测的特性(被称作"native bandwidth detection"),要进行带宽检测,客户端只要在成功连接 ...

  2. excel技巧

    1. 使文字自动适配方格大小. 自动调整行高(但是合并后的方格不行)

  3. 使用gulp将移动端px转为rem

    使用gulp的插件可以很方便的将xp转为rem,在布局的时候使用@1x .@2x布局,即10rem=device-width:@1x即设计图为320px,1rem对应的10px像素,相对的@2x即为布 ...

  4. Oracle 行转列,列转行

    一.行转列1.1.初始测试数据表结构:TEST_TB_GRADESql代码:1    create table TEST_TB_GRADE2    (3      ID        NUMBER(1 ...

  5. css相关问题

    display:none和visibility:hidden的区别? 前几天遇到的这个问题,表格布局:::::display:none 隐藏对应的元素,在文档布局中不再给它分配空间,它各边的元素会合拢 ...

  6. sql语句获取今天、昨天、近7天、本周、上周、本月、上月、半年数据

    话说有一文章表article,存储文章的添加文章的时间是add_time字段,该字段为int()类型的,现需要查询今天添加的文章总数并且按照时间从大到小排序,则查询语句如下: select * fro ...

  7. PAT 1015. 德才论 (25) JAVA

    宋代史学家司马光在<资治通鉴>中有一段著名的"德才论":"是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子 ...

  8. QT 文件操作

    QT提供了QFile类用于文件读写 QFile可以读写文本文件,也可以读写二进制文件 #include "widget.h" #include <QGridLayout> ...

  9. requirejs:性能优化-及早并行加载

    为了提高页面的性能,通常情况下,我们希望资源尽可能地早地并行加载.这里有两个要点,首先是尽早,其次是并行. 通过data-main方式加载要尽可能地避免,因为它让requirejs.业务代码不必要地串 ...

  10. 在SQL Server 2012中实现CDC for Oracle

    在上篇在SSIS 2012中使用CDC(数据变更捕获)中,介绍了如何在SSIS 2012中使用CDC,本文在此基础上介绍,如何通过Attunity提供的Change Data Capture Desi ...