题目大意:给定一个无向图,问共存在多少个割点。(割点:去掉此点后此图会断开连接)割点有两种存在:一种是第一次搜索的根节点,若其子节点数超过两个,则此点去掉后图会

断开连接,因此此点为割点;或者此点为搜索树的子节点,若其子节点的最早达到时间状态比其自身要晚,则说明此点不得不经过,并以此来更新其子节点,故其也是割点。

详见代码。

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
#define N 10100
vector<vector<int> >G;
int n, dfn[N], low[N], Time, father[N], vis[N];
void Init()
{
G.clear();
G.resize(n+);
memset(dfn, , sizeof(dfn));
memset(low, , sizeof(low));
memset(father, , sizeof(father));
memset(vis, , sizeof(vis));
Time = ;
}
void Trajin(int u, int fa)
{
father[u] = fa;
dfn[u] = low[u] = ++Time;
int i, len = G[u].size(), v;
for(i=; i<len; i++)
{
v = G[u][i];
if(!dfn[v])
{
Trajin(v, u);
low[u] = min(low[u], low[v]);
}
else if(fa!=v)
low[u] = min(low[u], dfn[v]);
}
}
int main()
{
while(scanf("%d", &n), n)
{
Init();
int a, b;
char x;
while(scanf("%d", &a), a)
{
while(scanf("%d%c", &b, &x))
{
G[a].push_back(b);
G[b].push_back(a);
if(x=='\n')break;
}
}
Trajin(, );
int ans = , RootSon = ;
for(int i=; i<=n; i++)
{
if(father[i]==)RootSon++;
else if(dfn[father[i]]<=low[i])
vis[father[i]] = ;
}
if(RootSon>)ans++;
for(int i=; i<=n; i++)
if(vis[i])ans++;
printf("%d\n", ans);
}
return ;
}

UVA315 (无向图求割点)的更多相关文章

  1. UVA-315 无向图求割点个数

    题意抽象: 给定一个无向图,输出割点个数. 割点定义:删除该点后,原图变为多个连通块. 考虑一下怎么利用tarjan判定割点: 对于点u和他相连的当时还未搜到的点v,dfs后如果DFN[u]<= ...

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

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

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

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

  4. uva 315 Network(无向图求割点)

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

  5. 无向图求割点 UVA 315 Network

    输入数据处理正确其余的就是套强联通的模板了 #include <iostream> #include <cstdlib> #include <cstdio> #in ...

  6. uva315(求割点数目)

    传送门:Network 题意:给出一张无向图,求割点的个数. 分析:模板裸题,直接上模板. #include <cstdio> #include <cstring> #incl ...

  7. poj 1523"SPF"(无向图求割点)

    传送门 题意: 有一张联通网络,求出所有的割点: 对于割点 u ,求将 u 删去后,此图有多少个联通子网络: 对于含有割点的,按升序输出: 题解: DFS求割点入门题,不会的戳这里

  8. poj 1144 Network 无向图求割点

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

  9. B - Network---UVA 315(无向图求割点)

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

  10. POJ 1144 无向图求割点

     学长写的: #include<cstdio>#include<cstdlib>#include<cmath>#include<iostream>#in ...

随机推荐

  1. Mac OS X使用快捷键改善窗口管理的六个方法

    http://www.macx.cn/thread-2085916-1-1.html 窗口全屏 ctrl+command+f

  2. [Eclipse] - Unicode properties editor

    在properpties文件中使用中文,需要将文件转成unicode. eclipse安装插件:PropertiesEditor 下载地址: http://propedit.sourceforge.j ...

  3. Openstack Neutron L2 Population

    Why do we need it, whatever it is? VM unicast, multicast and broadcast traffic flow is detailed in m ...

  4. windows server2012 r2 上 安装 IIS8.5

    一时间不知道怎么开头了,直接上图吧! 本人技术不高,正在学习中, 要是有 喜欢 .Net,觉得酷的,欢迎来 QQ群  316497348  交流分享!

  5. [HTML5]label标签使用以及建议

    for 属性规定 label 与哪个表单元素绑定. 隐式和显式的联系 标记通常以下面两种方式中的一种来和表单控件相联系:将表单控件作为标记标签的内容,这样的就是隐式形式,或者为 <label&g ...

  6. RMAN_学习笔记5_RMAN Catalog Script恢复目录脚本

    2014-12-24 Created By BaoXinjian

  7. 解决Windows8下Cisco Systems VPN Client的Reason 442: Failed to Enable Virtual Adapter错误

    Windows8下使用Cisco Systems VPN Client创建的Cisco IPSec VPN无法连接,提示Reason 442: Failed to Enable Virtual Ada ...

  8. 关于JQuery的一些知识点

    1.jQuery的入口函数 1.1 语法jQuery(document).read(function(){ }); $(function(){ });// ** window.onlaod = fun ...

  9. DEDE后台添加新变量出现:Request var not allow!的解决办法 相关案例演

    论坛上很多人都反馈说在后台添加新变量的时候会出现 "Request var not allow!" 的BUG错误,本文主要就是介绍如何去解决这个问题!下面看具体操纵:在DEDE根目 ...

  10. 【转】提高VR渲染速度的最好方法(经典转载)

    VR的基本渲染方法掌握起来并不难,但是最迫切需要解决的问题是VR的出图速度问题.动则需要数小时的渲染时间真的是很难以接受,我们从三个影响速度的参数结合网上一些高手的教程来分析一下. 一.Irradia ...