解题关键:割点模板题。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<vector>
  4. #include<stack>
  5. using namespace std;
  6. #define N 1010
  7. int n,m,ans,pd,son,cut[N],low[N],dfn[N];
  8. stack<int>s;
  9. const int maxn=1e5+;
  10. struct Edge{
  11. int nxt;
  12. int to;
  13. int w;
  14. }e[maxn];
  15. int head[maxn],cnt;
  16. void add_edge(int u,int v){
  17. e[cnt].to=v;
  18. e[cnt].nxt=head[u];
  19. head[u]=cnt++;
  20. }
  21. void tarjan(int u){
  22. low[u]=dfn[u]=++pd;
  23. for(int i=head[u];i!=-;i=e[i].nxt){
  24. int v=e[i].to;
  25. if(!dfn[v]){
  26. tarjan(v);
  27. low[u]=min(low[u],low[v]);
  28. if(low[v]>=dfn[u]&&u!=) cut[u]++;
  29. else if(u==) son++;
  30. }
  31. else low[u]=min(low[u],dfn[v]);
  32. }
  33. }
  34. int main(){
  35. while(scanf("%d",&n)==&&n){
  36. int u,v;
  37. memset(dfn,,sizeof dfn);
  38. memset(cut,,sizeof cut);
  39. memset(head,-,sizeof head);
  40. pd=ans=son=;
  41. while(scanf("%d",&u)==&&u){
  42. while(getchar()!='\n'){
  43. scanf("%d",&v);
  44. add_edge(u,v);
  45. add_edge(v,u);
  46. }
  47. }
  48. tarjan();
  49. for(int i=;i<=n;i++) if(cut[i]) ans++;
  50. if(son>) ans++;
  51. printf("%d\n",ans);
  52. }
  53. return ;
  54. }

[poj1144]Network(求割点模板)的更多相关文章

  1. POJ1144 Network(割点)题解

    Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are c ...

  2. poj1144 tarjan求割点

    poj1144 tarjan求割点 额,算法没什么好说的,只是这道题的读入非常恶心. 注意,当前点x是否是割点,与low[x]无关,只和low[son]和dfn[x]有关. 还有,默代码的时候记住分目 ...

  3. POJ1144 Network 无向图割点

    题目大意:求以无向图割点. 定义:在一个连通图中,如果把点v去掉,该连通图便分成了几个部分,则v是该连通图的割点. 求法:如果v是割点,如果u不是根节点,则u后接的边中存在割边(u,v),或者v-&g ...

  4. 求割点模板(可求出割点数目及每个割点分割几个区域)POJ1966(Cable TV Network)

    题目链接:传送门 题目大意:给你一副无向图,求解图的顶点连通度 题目思路:模板(图论算法理论,实现及应用 P396) Menger定理:无向图G的顶点连通度k(G)和顶点间最大独立轨数目之间存在如下关 ...

  5. UVA 315 求割点 模板 Tarjan

    D - D Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

  6. UVA 315 Network (模板题)(无向图求割点)

    <题目链接> 题目大意: 给出一个无向图,求出其中的割点数量. 解题分析: 无向图求割点模板题. 一个顶点u是割点,当且仅当满足 (1) u为树根,且u有多于一个子树. (2) u不为树根 ...

  7. 【lightoj-1063】Ant Hills(求割点)

    求割点模板题 #include <bits/stdc++.h> using namespace std; const int N = 10004; int dfn[N], low[N]; ...

  8. (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. poj1144 Network【tarjan求割点】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4319585.html   ---by 墨染之樱花 [题目链接]http://poj.org/p ...

随机推荐

  1. Unity3D GUI中的图片尾随鼠标旋转脚本

    var Mid : Texture2D; var mouse : Texture2D; //鼠标图片 var mousePs = Vector2.zero; //鼠标的位置 private var a ...

  2. [2018-10-10]记录一下Vue的一个问题

    最近用vue typescript SPA 做管理后台(ABP官网导出的vue项目模板),遇到一个错误,找了好久,虽然有相关资料,但发现都没解决,这里自己记录一下. Failed to mount c ...

  3. POJ - 2251 Dungeon Master 【BFS】

    题目链接 http://poj.org/problem?id=2251 题意 给出一个三维地图 给出一个起点 和 一个终点 '#' 表示 墙 走不通 '.' 表示 路 可以走通 求 从起点到终点的 最 ...

  4. eslint 配合 git (husky)

    为了保证每次提交的 git 代码是正确的,为此我们可以使用 eslint 配合 git hook, 在进行git commit 的时候验证eslint规范 如果 eslint 验证不通过,则不能提交. ...

  5. 跳转appStore评分

    跳转到AppStore让用户能够给我们的应用进行评分,有两种方法,一种是跳出应用,跳转到AppStore,进行评分.另一种是在应用内,内置AppStore进行评分. PS:appleID在https: ...

  6. python当前工作文件夹中创建空的.txt文件

    import os def new_txt(): a1='实线' b = os.getcwd() + '\\fazhandadao_test_txt\\' if not os.path.exists( ...

  7. (转)select、poll、epoll之间的区别总结[整理]

    select,poll,epoll都是IO多路复用的机制.I/O多路复用就通过一种机制,可以监视多个描述符,一旦某个描述符就绪(一般是读就绪或者写就绪),能够通知程序进行相应的读写操作.但select ...

  8. 机器学习 F1-Score, recall, precision

    在机器学习,模式识别中,我们做分类的时候,会用到一些指标来评判算法的优劣,最常用的就是识别率,简单来说,就是 Acc=Npre/Ntotal 这里的 Npre表示预测对的样本数,Ntotal表示测试集 ...

  9. STM32中IO口的8中工作模式

    该文摘自:http://blog.csdn.net/kevinhg/article/details/17490273 一.推挽输出:可以输出高.低电平,连接数字器件:推挽结构一般是指两个三极管分别受两 ...

  10. 使用svg的几种方式

    <!-- 图片,背景,框架引入svg文件 --> <img src="test.svg" alt=""> <?xml versio ...