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. python之数字类型小知识

    数字是表示计数的抽象事物,也是数学运算和推理的基础,所以,生活中数字是生活中无处不在的,那么,在python语言中运用数字有哪些小知识呢,不妨花点时间看一下这篇博文,牢记这些小知识. 整数类型中四种进 ...

  2. ython实现进程间的通信有Queue,Pipe,Value+Array等,其中Queue实现多个进程间的通信,而Pipe实现两个进程间通信,而Value+Array使用得是共享内存映射文件的方式,所以速度比较快

    1.Queue的使用 from multiprocessing import Queue,Process import os,time,random #添加数据函数 def proc_write(qu ...

  3. javascript中对编码的解读

    首先来一下js知识的巩固与复习 js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,deco ...

  4. js之数据类型(原始类型)

    JavaScript的数据类型分为两类:原始类型和对象类型.本文讨论的是原始类型.原始类型包括数字,字符串,和布尔值.但在JavaScript中有两个特殊的原始值null(空)和undefined(未 ...

  5. C# 移除数组中重复项

    方法一: static void Main(string[] args) { //看到数组的第一反应应该是排序 ,,,,,,,}; //去掉数组中重复的项 //先排序 arrayAsc(array); ...

  6. npm 设置淘宝镜像

    永久 npm config set registry https://registry.npm.taobao.org 直接安装 cnpm 替代 npm npm install -g cnpm --re ...

  7. element-ui select

    1. 组合 label <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...

  8. 第九章· MySQL的备份和恢复

    一.备份的原因 运维工作的核心简单概括就两件事: 1)第一个是保护公司的数据. 2)第二个是让网站能7*24小时提供服务(用户体验).  备份的原因 1)备份就是为了恢复. 2)尽量减少数据的丢失( ...

  9. 利用openssl完成自签发证书步骤--精华版

    #CentOS 7 CA目录 cd /etc/pki/CA #建立 demoCA 目录结构mkdir -p ./demoCA/{private,newcerts}touch ./demoCA/inde ...

  10. win32 控件的使用

    我们建立的项目都是基于对话框的win32项目,和主窗口一样对话框也是窗口的一种类型所以区别不是很大,所以我们再下面讲一下控件的使用(里面不要使用char,要开始使用WCHAR,他的很多函数都是wcs. ...