UVA 315 求割点 模板 Tarjan
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的更多相关文章
- UVA 315 Network (模板题)(无向图求割点)
<题目链接> 题目大意: 给出一个无向图,求出其中的割点数量. 解题分析: 无向图求割点模板题. 一个顶点u是割点,当且仅当满足 (1) u为树根,且u有多于一个子树. (2) u不为树根 ...
- UVA 315 求连通图里的割点
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20837 哎 大白书里求割点的模板不好用啊,许多细节理解起来也好烦..还好找了 ...
- 求割点 割边 Tarjan
附上一般讲得不错的博客 https://blog.csdn.net/lw277232240/article/details/73251092 https://www.cnblogs.com/colle ...
- 无向连通图求割点(tarjan算法去掉改割点剩下的联通分量数目)
poj2117 Electricity Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3603 Accepted: 12 ...
- [poj1144]Network(求割点模板)
解题关键:割点模板题. #include<cstdio> #include<cstring> #include<vector> #include<stack& ...
- 求割点模板(可求出割点数目及每个割点分割几个区域)POJ1966(Cable TV Network)
题目链接:传送门 题目大意:给你一副无向图,求解图的顶点连通度 题目思路:模板(图论算法理论,实现及应用 P396) Menger定理:无向图G的顶点连通度k(G)和顶点间最大独立轨数目之间存在如下关 ...
- [UVA315]Network(tarjan, 求割点)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- poj_1144Network(tarjan求割点)
poj_1144Network(tarjan求割点) 标签: tarjan 割点割边模板 题目链接 Network Time Limit: 1000MS Memory Limit: 10000K To ...
- poj1523 求割点 tarjan
SPF Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7678 Accepted: 3489 Description C ...
随机推荐
- 如何使用加多宝(jdb)在linux下调试Java程序
毕业时写了一段时间的C,那时候调试使用gdb,后来转了java,当时就想java程序怎么调试,找了一下,果然,那就是jdk自带的jdb windows里是这样的 Linux下是这样的 一般我在linu ...
- [转载]VS2005的工程用VS2010打开后,用VS2005不能打开的解决方法
首先,在“项目”菜单里,把项目属性“目标平台”改为框架2.0,保存退出. 然后,用记事本或用编辑文本文件的方式打开你的项目文件,后缀为.sln 第一行:把“Microsoft Visual Studi ...
- Fox新闻报道,帮助北朝鲜使用加密货币专家被捕
根据司法部的刑事诉讼,一名美国加密货币专家周四在洛杉矶被捕,原因是涉嫌帮助朝鲜使用加密货币逃避美国的制裁.网民都说敢帮助敌人,就应该关起来.
- LeetCode 腾讯精选50题--有效的括号
根据题意,第一反应就是使用栈,左右括号相匹配,则将左括号出栈,否则将左括号入栈. 这里我用数组配合“指针”模拟栈的入栈与出栈操作,初始时指针位置指向0,表示空栈,凡遇上左括号则直接入栈,若遇上有括号, ...
- 仍然有人在叫喊C语言已经过时了
现在,仍然有人在叫喊C语言已经过时了.还有什么值得学习的?看看现在使用Python.PHP和其他语言有多简单.谁去学旧的C语言?是真的吗?作者下载了这两种语言的底层源代码.由于空间的限制,它没有分析框 ...
- centos 查看ip
1.现象: 通过ip addr 查找Ip时,发现ens33中没有inet属性,如下图: 2.解决方法 打开网卡配置文件 /etc/sysconfig/network-scripts/ifcfg-ens ...
- TCP保活定时器
TCP有Keepalive功能,它和HTTP的Keepalive功能目的不一样.TCP服务器希望知道客户端是否崩溃.重新启动或者中间路由不通.保活定时器就提供这种功能. 在进一步介绍TCP的保活定时器 ...
- pv与pvc
目的: 为了屏蔽底层存储实现的细节, 让用户方便使用同时让管理员方便管理, 引入了pv与pvc两种资源对象实现对存储的管理子系统 pv: 对底层网络共享存储的抽象, 将共享存储定义为一种资源 pvc: ...
- 3.LVS的三种工作模式_TUN模式
1.TUN模式(Virtual Server via IP Tunneling) 采用NAT模式时,由于请求和响应的报文必须通过调度器地址重写,当客户请求越来越多时,调度器处理能力将成为瓶颈.为了解决 ...
- Windows bat脚本的for语句
Windows bat脚本的for语句基本形态如下: 在cmd窗口中:for %I in (command1) do command2 在批处理文件中:for %%I in (command1) do ...