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 ajax MTV与MVC 多对多创建方式

    MTV与MVC MTV模型(django): M:模型层(models.py) T:templates V:views MVC模型: M:模型层(models.py) V:视图层(views.py) ...

  2. .NET CORE API 使用Postman中Post请求获取不到传参问题

    开发中遇到个坑 记录下. 使用Postman请求core api 接口时,按之前的使用方法(form-data , x-www-form-urlencoded)怎么设置都无法访问. 最后采用raw写入 ...

  3. luogu题解P2486[SDOI2011]染色--树链剖分+trick

    题目链接 https://www.luogu.org/problemnew/show/P2486 分析 看上去又是一道强行把序列上问题搬运到树上的裸题,然而分析之后发现并不然... 首先我们考虑如何在 ...

  4. python之jupyter notebook

    jupyter是一种交互式计算和开发环境的笔记,ipython命令行比原生的python命令行更加友好和高效,还可以运行web版的界面,支持多语言,输出图形.音频.视频等功能. 安装 pip inst ...

  5. vue-app物理返回键跳到指定页面

    例如提交订单成功跳到了订单详情页面,再返回就又到了提交订单支付页面 我们需要返回到其他页面 1.挂载完成后,判断浏览器是否支持popstate mounted(){ if (window.histor ...

  6. OSCP-Kioptrix2014-2 漏洞利用

    pChart 2.1.3 文件包含漏洞 搜索漏洞 查看漏洞理由代码: hxxp://localhost/examples/index.php?Action=View&Script=%2f..% ...

  7. hadoop 中ALL Applications 中Tracking 下History查找不到MapReduce Job 日志

    运行一个Map Reduce job 想查看日志: 点击History ,找不到网页 解决办法如下: 1.其中有一个进程是需要启动的: Hadoop自带了一个历史服务器,可以通过历史服务器查看已经运行 ...

  8. SSH安装配置

    一.环境准备 二.SSH配置 1.root用户进入home目录,确实有无隐藏文件夹 .ssh cd ~ ls -lrta 2.有,则跳过本步骤:没有,执行如下命令 ##根据提示输入当前用户密码 ssh ...

  9. Java ==和equals的区别

    首先了解默认equals方法实现代码 public boolean equals(Object obj) { return (this == obj); } 1.== (1)对于基本数据类型的变量,& ...

  10. IIS 调试配置