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. hdu1305Immediate Decodability(字典树)

    这题看是否 这题能A是侥幸,解决的办法是先存一下输入的字符串,进行排序. Problem Description An encoding of a set of symbols is said to ...

  2. Ghost硬盘对拷

    Ghost硬盘对拷 优点:全盘完全100%对拷,包括原有操作系统也可使用.新硬盘对拷结束后,可直接插上电脑使用.消耗时间最短. 困难:对于第一次操作Ghost对拷的新人来说,需要严格对照图片步骤教程. ...

  3. 55. Jump Game(贪心)

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  4. Object-C-Foundation-数组排序

    系统类型排序; NSArray *goodsNames =@[@"computer",@"iphone",@"ipad"]; NSArray ...

  5. Python 迭代器切片

    函数itertools.islice() 正好适用于在迭代器和生成器上做切片操作 >>> def count(n): ... while True: ... yield n ... ...

  6. 20165207 Exp1 PC平台逆向破解

    20165207 Exp1 PC平台逆向破解 0.写在最前面 在做三个实验的前两个的时候,我还没有到博客里去看作业的要求.当时我的主机名是kali5207也就是用我的学号命名的,要求的是姓名全拼命名k ...

  7. 拉取远程仓库到本地错误The authenticity of host 'github.com (13.229.188.59)' can't be established.

    1.个人在github上面创建了仓库,通过本地的git拉取远程仓库到本地报错信息如下: 这是因为Git使用SSH连接,而SSH第一次连接需要验证GitHub服务器的Key.确认GitHub的Key的指 ...

  8. Linux基础命令---ar

    ar ar指令可以创建.修改库,也可以从库中提取单个模块.库是一个单独的文件,里面包含了按照特定结构组织起来的其他文件,我们称作member.归档文件通常是一个二进制文件,我们一般将归档文件当作库来使 ...

  9. netty4----日志框架的检查

    https://segmentfault.com/a/1190000005797595 2016年06月25日  ·  4.1k 次阅读 Netty4.x Internal Logger机制 nett ...

  10. angularjs 路由参数

    .state('classrooms',{ url: '/classrooms/:id' }) .state('classrooms',{ url: '/classrooms/{id}' }) .st ...