传送门:Network

题意:给出一张无向图,求割点的个数。

分析:模板裸题,直接上模板。

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 100000000
#define inf 0x3f3f3f3f
#define eps 1e-6
#define N 110
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PII pair<int,int>
using namespace std;
struct edge
{
int v,next;
edge(){}
edge(int v,int next):v(v),next(next){}
}e[N*N];
int n,step,top,tot;
int head[N],dfn[N],low[N],Stack[N];
bool instack[N],cutpoint[N];
void init()
{
tot=;step=;top=;
FILL(head,-);FILL(dfn,);
FILL(low,);FILL(instack,false);
FILL(cutpoint,false);
}
void addedge(int u,int v)
{
e[tot]=edge(v,head[u]);
head[u]=tot++;
}
void tarjan(int u,int fa)
{
int son=;
dfn[u]=low[u]=++step;
Stack[top++]=u;
instack[u]=true;
for(int i=head[u];~i;i=e[i].next)
{
int v=e[i].v;
if(v==fa)continue;
if(!dfn[v])
{
son++;
tarjan(v,u);
if(low[u]>low[v])low[u]=low[v];
//割点: 一个顶点u是割点,当且仅当满足(1)或(2)
//(1) u为树根,且u有多于一个子树
//(2) u不为树根,且满足存在(u,v)为树枝边,使得DFS(u)<=Low(v)
if(u!=fa&&low[v]>=dfn[u])
{
cutpoint[u]=true;
}
}
else if(low[u]>dfn[v])
{
low[u]=dfn[v];
}
}
//树根,分支数大于1
if(u==fa&&son>)cutpoint[u]=true;
instack[u]=false;
top--;
}
void solve()
{
for(int i=;i<=n;i++)
if(!dfn[i])tarjan(i,i);
int ans=;
for(int i=;i<=n;i++)
if(cutpoint[i])ans++;
printf("%d\n",ans);
}
int main()
{
int u,v;
while(scanf("%d",&n),n)
{
init();
while(scanf("%d",&u),u)
{
while(getchar()!='\n')
{
scanf("%d",&v);
addedge(u,v);
addedge(v,u);
}
}
solve();
}
}

uva315(求割点数目)的更多相关文章

  1. POJ 1144 Network(Tarjan求割点)

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

  2. UVA315:Network(求割点)

    Network 题目链接:https://vjudge.net/problem/UVA-315 Description: A Telephone Line Company (TLC) is estab ...

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

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

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

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

  5. 无向连通图求割点(tarjan算法去掉改割点剩下的联通分量数目)

    poj2117 Electricity Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3603   Accepted: 12 ...

  6. (转)Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)

    基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成多个 ...

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

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

  8. 【UVA10765】Doves and bombs (BCC求割点后联通块数量)

    题目: 题意: 给了一个联通无向图,现在问去掉某个点,会让图变成几个联通块? 输出的按分出的从多到小,若相等,输出标号从小到大.输出M个. 分析: BCC求割点后联通块数量,Tarjan算法. 联通块 ...

  9. UVA315 Network —— 割点

    题目链接:https://vjudge.net/problem/UVA-315 A Telephone Line Company (TLC) is establishing a new telepho ...

随机推荐

  1. SIX GOD

    SIX GOD是什么意思呢.?_百度知道 SIX GOD

  2. Java的LockSupport.park()实现分析

    LockSupport类是Java6(JSR166-JUC)引入的一个类,提供了主要的线程同步原语.LockSupport实际上是调用了Unsafe类里的函数,归结到Unsafe里,仅仅有两个函数: ...

  3. Bandwidth内存带宽測试工具

    本博文为原创,遵循CC3.0协议,转载请注明出处:http://blog.csdn.net/lux_veritas/article/details/24766015 ----------------- ...

  4. Makefile自动生成工具-----autotools的使用(详细)

    相信每个学习Linux的人都知道Makefile,这是一个很有用的东西,但是编写它是比较复杂,今天介绍一个它的自动生成工具,autotools的使用.很多GNULinux的的软件都是用它生成Makef ...

  5. 语音信号处理之(三)矢量量化(Vector Quantization)

    语音信号处理之(三)矢量量化(Vector Quantization) zouxy09@qq.com http://blog.csdn.net/zouxy09 这学期有<语音信号处理>这门 ...

  6. 一起talk GDB吧(第六回:GDB改动程序执行环境)

    各位看官们,大家好,上一回中我们说的是GDB查看信息的功能,而且说了怎样使用GDB查看程序执行时的 信息.这一回中,我们继续介绍GDB的调试功能:改动程序执行环境.当然了,我们也会介绍怎样使用GDB ...

  7. Windows下用Mingw编译Boost.Regex库

    下载Boost库,解压. 定位到regex库文件夹下. GCC所对应的MAKEFILE为gcc.mak 进入命令提示符下,输入make -f gcc.mak 这是如果直接按回车执行的话,会出现错误: ...

  8. Servlet过滤器——过滤器分析流量

    1.概述 Servlet过滤器可以对用户提交的数据或服务器返回的数据进行更改.任何到达服务器的请求都会首先经过过滤器的处理.本实例应用过滤器的这个特点,编写了一个在过滤器中统计网站流量的实例. 本实例 ...

  9. 控件编写:增强 TMEMO (一)(增加对WM_HSCROLL消息的处理)

    相信没有什么人对 MEMO 陌生了吧.尽管其组件的功能不错.但是,对它进行一些功能的改进,可以更好的使用. 有的时候,我们想要知道,当前的坐标是什么?甚至,想要在 滚动条滚动时触发一些事件. 但,TM ...

  10. 改变TPageControl的活动标签颜色

    设置PageControl的owndraw属性为TRUE. procedure TForm1.pgc1DrawTab(Control: TCustomTabControl; TabIndex: Int ...