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. django 模块创建 同步数据表 使用方法

    1 配置数据库   100行左右 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # 'NAME': 'student ...

  2. asp.net练习①——Application聊天室

    已经好几年没写过代码,重新练习起代码,在这做做笔记备忘. aspx页面js代码: <script type="text/javascript"> function sh ...

  3. Codeforces 1244D. Paint the Tree

    传送门 首先如果某个点的度数大于 $2$ 那么显然无解 然后考虑点的度数小于等于 $2$ 的情况 发现其实是一条链 一旦确定了链开头的两个点,后面的点的颜色都可以通过之前的点推出 所以直接枚举即可 # ...

  4. And Reachability CodeForces - 1169E (有向图可达性)

    大意: 给定序列$a$, 对所有的a[i]&a[j]>0, 从$i$向$j$连一条有向边, 给出$m$个询问$(x,y)$, 求是否能从$x$到达$y$. 裸的有向图可达性, 有向图可达 ...

  5. CentOS6.8安装Python3.6.3

    1.linux下安装python3 准备编译环境(环境如果不对的话,可能遇到各种问题,比如wget无法下载https链接的文件) yum install zlib-devel bzip2-devel ...

  6. 详解CSS居中布局技巧

    本文转自:https://zhuanlan.zhihu.com/p/25068655#showWechatShareTip一.水平居中元素: 1.通用方法,元素的宽高未知方式一:CSS3 transf ...

  7. SSE笔记

    1.8位加: *(__m128i*)(dest + i * 16) = _mm_add_epi8(*(__m128i*)(srcA + i * 16), *(__m128i*)(srcB + i * ...

  8. Laravel 表单验证创建“表单请求”实现自定义请求类

    按照文档创建表单请求自定义类以后,调用总是403页面,咨询大佬说: public function authorize() { // 在表单验证类的这个方法这里要返回true,默认返回false,这个 ...

  9. 点击登录页面成功后,后端返回数据需要保存,在另外一个页面,发送ajax请求的时候需要登录返回数据的其中的一部分当做参数然后拿到新的数据

    对于这个怎么操作首先我们要在登录的ajax请求中把后端的数据保存到sessionstorage中,代码如下 登录ajax $.ajax({ type:'post', url:xxxxxxxxx, da ...

  10. vue 编辑

    点击文字修改 <div class="baseInfo"> <p class="title">基本信息</p> <p ...