题目地址:

id=1144">POJ 1144

求割点。推断一个点是否是割点有两种推断情况:

假设u为割点,当且仅当满足以下的1条

1、假设u为树根,那么u必须有多于1棵子树

2、假设u不为树根。那么(u,v)为树枝边。当Low[v]>=DFN[u]时。

然后依据这两句来找割点就能够了。

代码例如以下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
int head[200], cnt, index1, ans;
int vis[200], low[200], dfn[200], ge[200];
struct node
{
int u, v, next;
}edge[2000];
void add(int u, int v)
{
edge[cnt].v=v;
edge[cnt].next=head[u];
head[u]=cnt++;
}
void tarjan(int u, int fa)
{
int son=0, i;
low[u]=dfn[u]=++index1;
vis[u]=1;
for(i=head[u];i!=-1;i=edge[i].next)
{
int v=edge[i].v;
son++;
if(!vis[v])
{
tarjan(v,u);
low[u]=min(low[v],low[u]);
if(u==1&&son>1||dfn[u]<=low[v]&&u!=1)
{
ge[u]++;
}
}
else if(v!=fa)
low[u]=min(low[u],dfn[v]);
}
}
void init()
{
memset(head,-1,sizeof(head));
cnt=0;
index1=ans=0;
memset(vis,0,sizeof(vis));
memset(dfn,0,sizeof(dfn));
memset(ge,0,sizeof(ge));
}
int main()
{
int n, i, j, u, v;
while(scanf("%d",&n)!=EOF&&n)
{
init();
while(scanf("%d",&u)!=EOF&&u)
{
while(getchar()!='\n')
{
scanf("%d",&v);
add(u,v);
add(v,u);
}
}
tarjan(1,-1);
for(i=1;i<=n;i++)
{
if(ge[i])
ans++;
}
printf("%d\n",ans);
}
return 0;
}

POJ 1144 Network(无向图连通分量求割点)的更多相关文章

  1. POJ 1144 Network(Tarjan求割点)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12707   Accepted: 5835 Descript ...

  2. POJ 1144 Network(tarjan 求割点个数)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17016   Accepted: 7635 Descript ...

  3. poj 1144 Network 无向图求割点

    Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...

  4. poj 1144 Network(无向图求割顶数)

    题目链接:poj 1144 题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数. 直接上大白书上的 ...

  5. POJ 1144 Network (求割点)

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

  6. poj 1144 Network 图的割顶判断模板

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8797   Accepted: 4116 Descripti ...

  7. poj 1523 SPF(tarjan求割点)

    本文出自   http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...

  8. poj1144 Network【tarjan求割点】

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

  9. [UVA315]Network(tarjan, 求割点)

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

随机推荐

  1. vue倒计时页面

    https://www.cnblogs.com/sichaoyun/p/6645042.html https://blog.csdn.net/sinat_17775997/article/detail ...

  2. iphone上做webapp时总会识别一串数字为手机号码并变黑显示

    iphone上网页里总会识别一串数字为手机号码并变黑显示 只需要在head里加上一个特别的meta即可 <meta name="format-detection" conte ...

  3. HDU 1841 Find the Shortest Common Superstring----KMP

    题意:给两个字符串,问包含这两个字符串的最小的字符串的长度 kmp返回匹配串长度 #include "iostream" #include<cstdio> #inclu ...

  4. 求LCA最近公共祖先的离线Tarjan算法_C++

    这个Tarjan算法是求LCA的算法,不是那个强连通图的 它是 离线 算法,时间复杂度是 O(m+n),m 是询问数,n 是节点数 它的优点是比在线算法好写很多 不过有些题目是强制在线的,此类离线算法 ...

  5. eclipse 导出burpsuite插件包含第三方lib包

    第一步:右键项目点击export: 2.选择Runable JAR file: 点击Finish后会爆出一个错误(Jar export finished with problems. See deta ...

  6. QueryDict对象

    所在的包: django.http.QueryDict HttpRequest 对象中的 GET 和 POST 属性 都是 QueryDict类型 与python字典不同:QueryDict对象一个键 ...

  7. 通过过滤器和增强request对象解决get提交请求服务器端乱码。

    1.表单用get方式提交 <%@ page language="java" contentType="text/html; charset=UTF-8" ...

  8. leetcode-Min Cost Climbing Stairs

    题目: On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you ...

  9. poj 3348(凸包面积)

    Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8063   Accepted: 3651 Description ...

  10. 华农oj Problem K: 负2进制【有技巧构造/待补】

    Problem K: 负2进制 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 51 Solved: 6 [Submit][Status][Web Boa ...