【题目描述】

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

【题目分析】
题目要求求割点,首先什么是割点呢?就是一个连通图/连通分量中将这个点去掉就不再是一个连通图的点。
我们想要求割点,很显然可以直接暴力,先在一个连通图里面删去这个点所有的边,如果变得不连通了就是割点。可是这样时间复杂度显然是不允许的。
我们再来仔细观察割点有什么特点:删去这个点就有一些点无法到达。
我们结合Trajan算法中的DFS搜索树进行分析,如果一个点是割点,如果他后面的子树就无法访问到前面的点,那么删去这个点,前面的点也就无法访问后面的点了,前后两部分无法相互访问,那说明这个点就是一个割点。我们如何判断后面的子树不会访问到前面的点呢?我们可以用Trajan算法中的LOW数组 ,如果子树的LOW数组的值比这个点的DFN的值还大说明这个点就是一个割点。
可是对于根节点(开始访问的点)来讲,就算这个点是一个割点后面的点也不会访问到他前面的点,但是这个根节点不同搜索树上的点是互相没有关系的,如果他有两个或者两个以上的搜索树,那么删去根节点也可以形成割点。但是对于一般的点,就算他有好几个儿子节点也不一定是一个割点,因为这些儿子之中有可能有之前访问过的点,但是对于访问过的点我们是不会放入这个搜索树的,所以不同搜索树有可能访问到同一个之前的点,这样就算删去这个点也可能有通路。但是对于根节点就无法访问到更前面的点了,所以就可以确定是一个割点。

总结一下,割点总共就两类:

  1. 含有两个或者两个以上子树的根节点u (u==root(u==root(u==root && son&gt;1)son&gt;1)son>1)
  2. 子树节点v的搜索树中不含有祖先节点的点u(u!=root(u!=root(u!=root && LOW[v]&gt;=DFN[u])LOW[v]&gt;=DFN[u])LOW[v]>=DFN[u])

【AC代码】

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<climits>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;typedef long long ll;
const int MAXN=105;
const int MAXM=MAXN*MAXN;
struct node
{int v,next;
}Edge[MAXM];
int head[MAXN],tot;
int DFN[MAXN],LOW[MAXN];
bool cnt[MAXN];
int vis[MAXN],Time;
int n,root,ans;void init()
{memset(head,0,sizeof(head));tot=0;memset(vis,0,sizeof(vis));Time=0;memset(cnt,0,sizeof(cnt));
}void AddEdge(int u,int v)
{tot++;Edge[tot].v=v; Edge[tot].next=head[u];head[u]=tot;
}void read()
{int u,v;while(~scanf("%d",&u) && u){while(getchar()!='\n'){scanf("%d",&v);AddEdge(u,v); AddEdge(v,u);}}
}void Trajan(int x,int fa)
{int v;int son=0;DFN[x]=LOW[x]=++Time;vis[x]=1;for(int i=head[x];i;i=Edge[i].next){v=Edge[i].v;if(vis[v]==0){Trajan(v,x);son++;LOW[x]=min(LOW[x],LOW[v]);if(x==root &&son>1 || x!=root && LOW[v]>=DFN[x]){cnt[x]=true;}}else if(vis[v]==1){LOW[x]=min(LOW[x],DFN[v]);}}vis[x]==2; //说明这个搜索数完结了和其他的点就没有什么关系了,因此设为2其他点就不会访问到
}void solve()
{ans=0;root=1;for(int i=1;i<=n;i++){if(!vis[i]){root=i;Trajan(i,i);}}for(int i=1;i<=n;i++){if(cnt[i]) ans++;}printf("%d\n",ans);
}int main()
{while(~scanf("%d",&n) && n){init();read();solve();}return 0;
}

POJ-1144 Network——Trajan+割点相关推荐

  1. POJ 1144 Network(无向图连通分量求割点)

    题目地址:POJ 1144 求割点.推断一个点是否是割点有两种推断情况: 假设u为割点,当且仅当满足以下的1条 1.假设u为树根,那么u必须有多于1棵子树 2.假设u不为树根.那么(u,v)为树枝边. ...

  2. POJ 1144 Network (求割点)

    题意: 给定一幅无向图, 求出图的割点. 割点模板:http://www.cnblogs.com/Jadon97/p/8328750.html 分析: 输入有点麻烦, 用stringsteam 会比较 ...

  3. POJ 1144 Network 图论

    题目地址:http://poj.org/problem?id=1144 题目大意:多组数据,每组数据以0结束,文件也以0结束.对于每组数据第一行n表示点数,接下来至多n行,每行至多n个数,第i个数表示 ...

  4. POJ 1144 Network

    无向图求割点,开始看题后不知道求什么,看了discussi才知道是求割点,然后就在网上找了找关于割点的知识.然后在http://blog.csdn.net/xinghongduo/article/de ...

  5. 【割边缩点】解题报告:POJ - 3694 - Network(Tarjan割边缩点 + LCA + 并查集优化)

    POJ - 3694 - Network 给定一张N个点M条边的无向连通图,然后执行Q次操作,每次向图中添加一条边,并且询问当前无向图中"桥"的数量.N≤105,M≤2∗105,Q ...

  6. POJ 1236 Network of Schools(强连通 Tarjan+缩点)

    POJ 1236 Network of Schools(强连通 Tarjan+缩点) ACM 题目地址:POJ 1236 题意:  给定一张有向图,问最少选择几个点能遍历全图,以及最少加入�几条边使得 ...

  7. uva 315 (poj 1144 求割点)

    题意:给你一张无向图,求割点的个数. 思路:输入稍微处理一下接着直接套模版. 1 #include <iostream> 2 #include <cstdio> 3 #incl ...

  8. poj 1144 割点和桥

    割点: 对于一个无向的连通图,如果删除一个点u及其相关的边,会是的新的图不连通,那么点u就称为图G的一个割点. 记得   首先这个图是  无向的 其次是连通的. vis[]记录的是节点v当前的访问状态 ...

  9. Network POJ - 1144

    点击打开链接 套的啊哈算法上的板子 当初学割点割边板子都是靠背的.. 主要是时间戳这个东西不太理解 就是以某一点为根生成一棵搜索树 意义就是记录每个点的时间戳(感觉也可以理解为树的层数) 越靠后被遍历 ...

  10. [tarjan] poj 1236 Network of Schools

    主题链接: http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS   Memory Limit: 10000K To ...

最新文章

  1. DEDECMS v5.5 GBK Final 的一个鸡肋漏洞
  2. HTTP缓存字段总结
  3. 5 步助你成为一名优秀的 Docker 代码贡献者
  4. CString::Format
  5. md发布test-1 md发布test-1md发布test-1md发布test-1md发布test-1md发布test-1md发布test-1md发布test-1md发布test-1md发布test-
  6. PHP + NGINX 控制视频文件播放,并防止文件下载
  7. 名片识别信息分类python_python体验名片识别OCR
  8. linux mysql5.7启动失败/tmp/mysql.sock ?
  9. Frequent values【线段树】
  10. 【操作系统】Semaphore处理读者-写者问题
  11. H2O Wave教程---基于浏览器的实时显示工具---教程01
  12. 面向对象的理解及相关概念(封装,继承,多态)
  13. 《3D打印:正在到来的工业革命》——1.1节3D 技术打印是如何工作的
  14. 云计算之openstack(N版)neutron网络服务最佳实践
  15. 事件 event
  16. java匿名内部类 内部类_java中的匿名内部类详细总结
  17. 蛮力法 第4关:韩信点兵问题
  18. 驼峰式命名法python_驼峰命名法
  19. xml文件怎么转换成wps_xml文件转word文档 怎么将XML文档转成WORD文档
  20. 2.语法特性(组合数据类型)

热门文章

  1. iOS框架引见--媒体层
  2. Win10系统怎样让打开图片方式为照片查看器
  3. 063.django之模板层
  4. iOS16 系统更新教程,测试版描述文件下载
  5. 【2019秋招】携程数据分析岗笔试编程题——画心形
  6. word、excel、PPT快捷键一览
  7. “没拿到一毛钱股份的老公”刷爆朋友圈 吃瓜群众雾里看花
  8. R语言使用median函数计算dataframe数据中特定数据列的中位数、如果包含NA值则需要设置na.rm参数为TRUE
  9. display:HDCP协议简述
  10. 5G网络架构 — 接入网/传输网/核心网