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

思路:

求割点模板题,再输入那里WA了两发orz...,以为最多只能n行就加了个while。

因为是个无向图,所以tarjan(1)就行了,根节点也就只有1了

判断割点的方法:

1.是根节点:如果son>=2就是割点

2.不是根节点:如果low[v]>=dfn[x]那么x就是割点

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<iostream>
#include<algorithm>
#include<sstream>
#define ll long long
const int N=110;
const int INF=1e9;
using namespace std;
int cnt;
int dfn[N],low[N];
vector<int> g[N];
map<int,int> ans; void tarjan(int x){
dfn[x]=low[x]=cnt++;
int son=0;
for(int i=0;i<g[x].size();i++){
int v=g[x][i];
if(!dfn[v]){
son++;
tarjan(v);
low[x]=min(low[x],low[v]);
if(low[v]>=dfn[x] && dfn[x]!=1) ans[x]++;
else if(x==1 && son>1){
ans[x]++;
}
}
else{
low[x]=min(low[x],dfn[v]); }
} }
void init(){
cnt=1;
for(int i=0;i<N;i++) g[i].clear();
ans.clear();
memset(dfn,0,sizeof(dfn));
memset(low,0,sizeof(low));
}
int main(){
int n,a,b;
string s;
while(~scanf("%d",&n) && n){
init();
getchar();
while(true){
getline(cin,s);
stringstream ss(s);
ss>>a;
if(!a) break;
while(ss>>b && b){
g[a].push_back(b);
g[b].push_back(a);
}
}
tarjan(1);
cout<<ans.size()<<endl;
}
return 0;
}

POJ1144 Network(割点)题解的更多相关文章

  1. POJ1144 Network 题解 点双连通分量(求割点数量)

    题目链接:http://poj.org/problem?id=1144 题目大意:给以一个无向图,求割点数量. 这道题目的输入和我们一般见到的不太一样. 它首先输入 \(N\)(\(\lt 100\) ...

  2. POJ1144:Network(无向连通图求割点)

    题目:http://poj.org/problem?id=1144 求割点.判断一个点是否是割点有两种判断情况: 如果u为割点,当且仅当满足下面的1条 1.如果u为树根,那么u必须有多于1棵子树 2. ...

  3. poj1144 Network【tarjan求割点】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4319585.html   ---by 墨染之樱花 [题目链接]http://poj.org/p ...

  4. [poj1144]Network(求割点模板)

    解题关键:割点模板题. #include<cstdio> #include<cstring> #include<vector> #include<stack& ...

  5. POJ1144 Network 无向图割点

    题目大意:求以无向图割点. 定义:在一个连通图中,如果把点v去掉,该连通图便分成了几个部分,则v是该连通图的割点. 求法:如果v是割点,如果u不是根节点,则u后接的边中存在割边(u,v),或者v-&g ...

  6. UVA315 Network —— 割点

    题目链接:https://vjudge.net/problem/UVA-315 A Telephone Line Company (TLC) is establishing a new telepho ...

  7. ZOJ1311, POJ1144 Network

    题目描述:TLC电话线路公司正在新建一个电话线路网络.他们将一些地方(这些地方用1到N的整数标明,任何2个地方的标号都不相同)用电话线路连接起来.这些线路是双向的,每条线路连接2个地方,并且每个地方的 ...

  8. poj 1144 Network(割点)

    题目链接: http://poj.org/problem?id=1144 思路分析:该问题要求求出无向联通图中的割点数目,使用Tarjan算法即可求出无向联通图中的所有的割点,算法复杂度为O(|V| ...

  9. [POJ1144]Network

    来源:Central Europe 1996 思路:Tarjan求割点. 一个点$x$为割点当且仅当: 1.$x$为根结点且有两棵不相交的子树. 2.$x$不为根结点且它的子树中没有可以返回到$x$的 ...

随机推荐

  1. Python开发【数据结构】:字典内部剖析

    字典内部剖析 开篇先提出几个疑问: 所有的类型都可以做字典的键值吗? 字典的存储结构是如何实现的? 散列冲突时如何解决? 最近看了一些关于字典的文章,决定通过自己的理解把他们写下来:本章将详细阐述上面 ...

  2. CCO2017 Vera and Trail Building 构造+图论

    正解:构造+图论 解题报告: 找了半天才找到的传送门! 先简要表达下题意 一个图上,如果存在(a,b)满足a<b且存在从a到b再回到a的路径,每条道路被经过至多一次,我们称(a,b)为完美点对试 ...

  3. 前端 HTML 常用标签 head标签相关内容

    HTML常用标签 head标签 我们首先来介绍一下head标签的主要内容和作用,文档的头部描述了文档的各种属性和信息,包括文档的标题.编码方式及URL等信息,这些信息大部分是用于提供索引,辩认或其他方 ...

  4. js-jquery-对象与JSON字符串互相转换

    1:jQuery插件支持的转换方式 代码如下: String→Object$.parseJSON( jsonstr ); //jQuery.parseJSON(jsonstr),可以将json字符串转 ...

  5. java-信息安全(八)-迪菲-赫尔曼(DH)密钥交换【不推荐,推荐Oakley】

    概述 信息安全基本概念: DH(Diffie–Hellman key exchange,迪菲-赫尔曼密钥交换) DH 是一种安全协议,,一种确保共享KEY安全穿越不安全网络的方法,它是OAKLEY的一 ...

  6. 【剑指offer】从上往下打印二叉树

    一.题目: 从上往下打印出二叉树的每个节点,同层节点从左至右打印. 二.思路: 用队列,用根节点初始化队列,然后依次从队列中取出节点,先把当前节点输出,并把左右子树分别放入队列,直到队列为空.欧了. ...

  7. 让人抓狂的MySQL安装-8.0.12版本

    今天一个下午就做了一件事,把MySQL安装成功,安装的过程让人很狂躁.于是一边骂,一边查错,才把这个软件给安装成功了. 详细的安装步骤,这里就不赘述了.参见https://blog.csdn.net/ ...

  8. Thread类的常见问题

    void waitForSignal() { Object obj = new Object(); synchronized(Thread.currentThread()) { obj.wait(); ...

  9. Iterator源码解读

    //继承关系 public interface Inteator { boolean hasNext(); Object next(); } public interface Iterable { I ...

  10. selenium webdriver testng自动化测试数据驱动

    selenium webdriver testng自动化测试数据驱动 selenium webdriver testng自动化测试数据驱动 一.数据驱动测试概念 数据驱动测试是相同的测试脚本使用不同的 ...