Network
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 12521   Accepted: 5760

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

Hint

You need to determine the end of one line.In order to make it's easy to determine,there are no extra blank before the end of each line.

Source

题意:

就要给你一个图,求有多少个割点

题解:

tarjan求割点的模板

何为割点?

也就是题目中的关键点。在一个无向图中,去掉一个点,这个无向图会变成多个子图,那么这个点就叫做割点

同理,割边也是如此,如果去掉一条边,能让无向图变成多个子图,那么这条边叫做割边,所谓的桥。

那么tarjan是如何求的割点的呢?

dfn:代表这个节点的深度
low:代表这个节点能通过反向边能到达到最浅深度(初始设为这个节点的深度)

如果u为割点,当且仅当满足下面的1/2

1、如果u为树根,那么u必须有多于1棵子树

2、如果u不为树根,那么(u,v)为树枝边,当Low[v]>=DFN[u]时。

割点的求法倒是看明白了,条件1的意思是若为根,下面如果只有一颗子树,也就是整个图是强连通,那么去掉根节点,肯定不会变成多个子图,因此也不会成为割点。只有大于一颗子树,去掉根节点,才会有两个或者2个以上的子图,从而才能成为割点

条件2也比较好理解,u不为树根,那么u肯定有祖先,如果存在Low【v】>=DFN【u】时,表示u的子孙只能通过u才能访问u的祖先,这也就是说,不通过u,u的子孙无法访问u的祖先,那么如果去掉u这个节点,就会至少分为两个子图,一个是u祖先,一个是u子孙的。

ps:输入有点麻烦。以换行结尾可以写成while(getchar() != '\n'),其他没什么难度了。

AC代码:

#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
#define N 1010
int n,m,cnt,pd,son,cut[N],low[N],dfn[N];
bool vis[N];
stack<int>s;
vector<int>grap[N];
void tarjan(int v){
low[v]=dfn[v]=++pd;
for(int i=;i<grap[v].size();i++){
int w=grap[v][i];
if(!dfn[w]){
tarjan(w);
low[v]=min(low[v],low[w]);
if(low[w]>=dfn[v]&&v!=) cut[v]++;
else if(v==) son++;
}
else{
low[v]=min(low[v],dfn[w]);
}
}
}
int main(){
while(scanf("%d",&n)==&&n){
int u,v;
memset(low,,sizeof low);
memset(dfn,,sizeof dfn);
memset(cut,,sizeof cut);
memset(vis,,sizeof vis);
memset(grap,,sizeof grap);
pd=;son=;cnt=;
while(scanf("%d",&u)==&&u){
while(getchar()!='\n'){
scanf("%d",&v);
grap[u].push_back(v);
grap[v].push_back(u);
}
}
tarjan();
for(int i=;i<=n;i++) if(cut[i]) cnt++;
if(son>) cnt++;
printf("%d\n",cnt);
}
return ;
}

poj1144的更多相关文章

  1. 【poj1144】 Network

    http://poj.org/problem?id=1144 (题目链接) 题意 求无向图的割点. Solution Tarjan求割点裸题.并不知道这道题的输入是什么意思,也不知道有什么意义= =, ...

  2. [POJ1144][BZOJ2730]tarjan求割点

    求割点 一种显然的n^2做法: 枚举每个点,去掉该点连出的边,然后判断整个图是否联通 用tarjan求割点: 分情况讨论 如果是root的话,其为割点当且仅当下方有两棵及以上的子树 其他情况 设当前节 ...

  3. POJ1144(割点入门题)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11378   Accepted: 5285 Descript ...

  4. poj1144 tarjan求割点

    poj1144 tarjan求割点 额,算法没什么好说的,只是这道题的读入非常恶心. 注意,当前点x是否是割点,与low[x]无关,只和low[son]和dfn[x]有关. 还有,默代码的时候记住分目 ...

  5. poj1144 求不同割点的个数

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

  6. POJ1144 Network 无向图的割顶

    现在打算重新学习图论的一些基础算法,包括像桥,割顶,双连通分量,强连通分量这些基础算法我都打算重敲一次,因为这些量都是可以用tarjan的算法求得的,这次的割顶算是对tarjan的那一类算法的理解的再 ...

  7. ZOJ1311, POJ1144 Network

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

  8. poj1144 Network【tarjan求割点】

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

  9. POJ1144(割点)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12551   Accepted: 5771 Descript ...

随机推荐

  1. 通过FTP连接Azure上的网站

    下载发布文件 使用记事本(或其他文本工具)打开 找到ftp连接地址以及用户名.密码 使用ftp工具进行连接 输入相应参数,连接即可

  2. SharePoint 2013 调用WCF服务简单示例

    内容比较简单,主要记录自己使用SharePoint 2013WCF服务遇到的小问题和小经验,分享给大家,希望能够给需要的人有所帮助.好吧,进入正题! 第一部分 SharePoint 2013调用自带W ...

  3. 读取XML绑定TreeNode

    <asp:TreeView ID="treeview" OnClick="TreeViewCheckBox_Click()" runat="se ...

  4. svn 服务器不能看log问题

    Subversion “show log” is offline 1.将/srv/svn/repos/ path svnserve.conf 里的 none-access = read 修改为none ...

  5. C安全编码--数组

    建议和规则 建议: 理解数组的工作方式 获取数组的长度时不要对指针应用sizeof操作符 显示地指定数组的边界,即使它已经由初始化值列表隐式地指定 规则: 保证数组索引位于合法的范围内 在所有源文件中 ...

  6. 利用Handler访问网络数据

    废话不多白吃,代码如下: 1.MainActivity package com.yz.day11_22_handler;import android.app.Activity;import andro ...

  7. iOS设计模式之观察者模式

    观察者模式 基本理解 观察者模式又叫做发布-订阅(Publish/Subscribe)模式. 观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态发生变化时 ...

  8. Android bitmap高效显示和优化

    第一部分:Bitmap高效显示 应用场景:有时候我们想在界面上显示一个网络图片或者显示一张本地的图片,但是图片本身是很大的有几兆,但是显示的位置很小或者说我们可以用更小的图片来满足这样的需求,如果把整 ...

  9. android 之 桌面的小控件AppWidget

    AppWidget是创建的桌面窗口小控件,在这个小控件上允许我们进行一些操作(这个视自己的需要而定).作为菜鸟,我在这里将介绍一下AppWeight的简单使用. 1.在介绍AppWidget之前,我们 ...

  10. .net串口通信

    背景: 前一段时间需要写一个向蓝牙模块发消息的功能. 对蓝牙的机制不太了解,所以一直在查资料, 但始终没找到我需要的东西,还误以为需要配套的一套开发模板和开发包, 偶然间发现只需要简单的串口通信,并且 ...