D - D

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

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
题意:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x7f7f7f7f
#define FOR(i,n) for(int i=1;i<=n;i++)
#define CT continue;
#define PF printf
#define SC scanf vector<int> G[105];
int ans=0,pre[105],low[105],dfs_clock,mp[105][105]; void Trajan(int u,int par)
{
pre[u]=low[u]=++dfs_clock;
int child=0,iscut=0;
for(int i=0;i<G[u].size();i++){
int v=G[u][i];
if(!pre[v]){
child++;
Trajan(v,u);
low[u]=min(low[u],low[v]);
if(low[v]>=pre[u]) iscut=1;
}
else if(v!=par) low[u]=min(low[u],pre[v]);//反向边更新,模拟训练指南313页上图
}
if(child==1&&par==-1) iscut=0;//删除顶点
if(iscut) ans++;
} int main()
{
int n,u;
while(~scanf("%d",&n)&&n)
{
MM(mp,0);
FOR(i,n) G[i].clear();
while(~scanf("%d",&u)&&u){
while(1){
int v;char c;
SC("%d%c",&v,&c);
mp[u][v]=mp[v][u]=1;
if(c=='\n') break;
}
}
FOR(i,n) for(int j=i+1;j<=n;j++) if(mp[i][j]) {
G[i].push_back(j);
G[j].push_back(i);
} MM(pre,0);
MM(low,0);
ans=dfs_clock=0;
FOR(i,n) if(!pre[i]) Trajan(i,-1);//发现新的联通块
PF("%d\n",ans);
}
return 0;
}

  

 

UVA 315 求割点 模板 Tarjan的更多相关文章

  1. UVA 315 Network (模板题)(无向图求割点)

    <题目链接> 题目大意: 给出一个无向图,求出其中的割点数量. 解题分析: 无向图求割点模板题. 一个顶点u是割点,当且仅当满足 (1) u为树根,且u有多于一个子树. (2) u不为树根 ...

  2. UVA 315 求连通图里的割点

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20837 哎 大白书里求割点的模板不好用啊,许多细节理解起来也好烦..还好找了 ...

  3. 求割点 割边 Tarjan

    附上一般讲得不错的博客 https://blog.csdn.net/lw277232240/article/details/73251092 https://www.cnblogs.com/colle ...

  4. 无向连通图求割点(tarjan算法去掉改割点剩下的联通分量数目)

    poj2117 Electricity Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3603   Accepted: 12 ...

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

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

  6. 求割点模板(可求出割点数目及每个割点分割几个区域)POJ1966(Cable TV Network)

    题目链接:传送门 题目大意:给你一副无向图,求解图的顶点连通度 题目思路:模板(图论算法理论,实现及应用 P396) Menger定理:无向图G的顶点连通度k(G)和顶点间最大独立轨数目之间存在如下关 ...

  7. [UVA315]Network(tarjan, 求割点)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  8. poj_1144Network(tarjan求割点)

    poj_1144Network(tarjan求割点) 标签: tarjan 割点割边模板 题目链接 Network Time Limit: 1000MS Memory Limit: 10000K To ...

  9. poj1523 求割点 tarjan

    SPF Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7678   Accepted: 3489 Description C ...

随机推荐

  1. sort()方法的用法,参数以及排序原理

    sort() 方法用于对数组的元素进行排序,并返回数组.默认排序顺序是根据字符串Unicode码点.语法:arrayObject.sort(sortby):参数sortby可选.规定排序顺序.必须是函 ...

  2. 百度后端C++电话一面

    Json.XML差异?说全点,能想到的所有差异.然后protobuf不小心被我提出来了,开始扯三个的差异....然后问优缺点.服务端客户端使用及接口更新的影响范围如何缩小 左值,右值区别 map用什么 ...

  3. 怎样理解 instanceof

    instanceof 运算符用来判断一个对象在其原型链中是否存在一个构造函数的 prototype 属性. 也就是说, instanceof 判断的实际上是某个对象是否为某个构造函数的实例, 因为es ...

  4. mysql解决fail to open file的方法

    由于没有安装有mysql的可视化工具,在使用cmd导入sql文件时,使用source 命令时出现 fail to open file的错误,各种查找后使用以下方法解决了: 1.首先进入mysql数据库 ...

  5. O051、Create Volume 操作 (Part II)

    参考https://www.cnblogs.com/CloudMan6/p/5612147.html       1.cinder-scheduler 也会启动一个工作流 volume_create_ ...

  6. Linux之curl

    简介 curl 是常用的命令行工具,用来请求 Web 服务器.它的名字就是客户端(client)的 URL 工具的意思. 它的功能非常强大,命令行参数多达几十种.如果熟练的话,完全可以取代 Postm ...

  7. 数组通常在JS中使用

    数组通常在JS中使用,例如具有相同名称的多个输入.如果它们是动态生成的,则需要在提交时确定它们是否是数组.如果(文件).MyList.长度!=“未定义”)此用法不正确.正确的是如果(文件.MyList ...

  8. VS2012隐藏输出窗口的快捷键是什么。

    纯属用键盘无法直接关闭这个窗口.有一个变通的方法是,先切换到这个输出窗口(标题呈现高亮的蓝色),使用Alt+W打开窗口菜单,选H隐藏就可以关闭.使用Ctrl+Alt+o可再次打开.按ESC就可以了.我 ...

  9. Oracle子句【group by、having】

    [分组查询]关键字:group by 分组字段名,分组字段名... --注意1:分组后,在select语句中只允许出现分组字段和多行函数 --注意2:如果是多字段分组,先按第一字段分组,然后每个小组继 ...

  10. Django静态资源配置

    Settings文件设置 INSTALLED_APPS 设置 确保 django.contrib.staticfiles 添加到INSTALLED_APPS中 默认是已经添加上的 INSTALLED_ ...