Network

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.
思路:就是求割点没什么说的;就是输入小心点
  

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
int dfn[];
int low[];
int head[];
int ans[];
int visit[];
int index,root,son,node,jiedge;
struct is
{
int u,v;
int next;
}edge[];
void add(int x,int y)
{
jiedge++;
edge[jiedge].u=x;
edge[jiedge].v=y;
edge[jiedge].next=head[x];
head[x]=jiedge;
jiedge++;
edge[jiedge].u=y;
edge[jiedge].v=x;
edge[jiedge].next=head[y];
head[y]=jiedge;
}
void dfs(int u)
{
for(int i=head[u];i;i=edge[i].next)
{
int v=edge[i].v;
if(visit[v]==)
{
visit[v]=;++index;
dfn[v]=low[v]=index;
dfs(v);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u])
{
if(u==root)
son++;
else
ans[u]++;
}
}
else
low[u]=min(low[u],dfn[v]);
}
}
void trajan()
{
memset(visit,,sizeof(visit));
memset(ans,,sizeof(ans));
index=;
root=;
son=;
low[]=dfn[]=;
visit[]=;
dfs();
}
int main()
{
int u,v;
int flag=;
while(scanf("%d",&node)!=EOF)
{
memset(head,,sizeof(head));
jiedge=;
if(node==)break;
while()
{
int u,v;
scanf("%d",&u);
if(!u)break;
while(getchar()!='\n')
{
scanf("%d",&v);
add(u,v);
}
}
trajan();
int answer=;
if(son>)
answer++;
for(int i=;i<=node;i++)
if(ans[i])
answer++;
printf("%d\n",answer);
}
return ;
}

poj 1144 Network 无向图求割点的更多相关文章

  1. POJ 1144 Network (求割点)

    题意: 给定一幅无向图, 求出图的割点. 割点模板:http://www.cnblogs.com/Jadon97/p/8328750.html 分析: 输入有点麻烦, 用stringsteam 会比较 ...

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

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

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

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

  4. poj 1144 (Tarjan求割点数量)

    题目链接:http://poj.org/problem?id=1144 描述 一个电话线公司(简称TLC)正在建立一个新的电话线缆网络.他们连接了若干个地点分别从1到N编号.没有两个地点有相同的号码. ...

  5. POJ 1144 Network —— (找割点)

    这是一题找无向图的割点的模板题,割点的概念什么的就不再赘述了.这里讲一下这个模板的一个注意点. dfs中有一个child,它不等于G[u].size()!理由如下: 如上图,1的size是2,但是它的 ...

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

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

  7. POJ 3694 Network(无向图求桥+重边处理+LCA)

    题目大意: 给你一个无向图,然后再给你一个Q代表有Q次询问,每一次加一条边之后还有几座桥.在这里要对重边进行处理. 每次加入一条边之后,在这条搜索树上两个点的公共祖先都上所有点的桥都没了. 这里重边的 ...

  8. poj 1523 SPF 无向图求割点

    SPF Description Consider the two networks shown below. Assuming that data moves around these network ...

  9. POJ 1144 Network(Tarjan求割点)

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

随机推荐

  1. Linux实验楼学习之三

    查看用户 who am i or who mom likes who 命令其它常用参数 参数 说明 -a 打印能打印的全部 -d 打印死掉的进程 -m 同am i,mom likes -q 打印当前登 ...

  2. soapUI-property Transfer

    1.1.1  Property Transfer 创建或双击现有的Property-Transfer TestStep将打开以下窗口: 左侧的列表显示了此TestStep中配置的传输,添加和管理所需的 ...

  3. SQL CASE 多条件用法

    Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex          WHEN '1' THEN '男'          WHEN '2' THEN ...

  4. Bootstrap学习笔记-布局

    Bootstrap学习笔记-布局 默认是响应式布局,就是你在改变页面的时候也不会出现乱的现象. <html><head> <meta charset="utf- ...

  5. VS2010的快捷键;VS2012变化的快捷键

    注释::VS2010是(Ctrl+E,C),VS2012是(Ctrl+K, Ctrl+C),实际操作,按住Ctrl键不放,先按K键,再按C键.相当于Ctrl+K加 Ctrl+C的组合键 反註解:VS2 ...

  6. python getctime() 文件最后一次的改变时间

    Return the metadata change time of a file,reported by os.stat() def mm(): file_name=r'c:\temp.txt' f ...

  7. Spring,Struts2,MyBatis,Activiti,Maven,H2,Tomcat集成(四)——Activiti集成

    1.添加Activiti Maven依赖: <!-- ==============================activiti=========================== --&g ...

  8. centos 安装sftp服务

    打开命令终端窗口,按以下步骤操作. 0.查看openssh的版本 ssh -V 使用ssh -V 命令来查看openssh的版本,版本必须大于4.8p1,低于的这个版本需要升级.  1.创建sftp组 ...

  9. 2016NOI冬令营day2

    早上起来发现头不痛了(还是咳) : | 上午先讲自然语言处理!完全不考!完全不涉及!一开始挺有兴趣,后面就完全听不懂了 : | 后来又讲了几道IOI题目(自称只是op),然后就是  从信息熵到数据压缩 ...

  10. INNODB引擎概述

    INNODB存储引擎的历史概述: INNODB存储引擎是OLTP应用中核心表的首选存储引擎. INNODB存储引擎包含在所有mysql数据库的二进制发行版本中.早期其版本随着mysql数据库的更新而更 ...