uva315(求割点数目)
传送门: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(求割点数目)的更多相关文章
- POJ 1144 Network(Tarjan求割点)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12707 Accepted: 5835 Descript ...
- UVA315:Network(求割点)
Network 题目链接:https://vjudge.net/problem/UVA-315 Description: A Telephone Line Company (TLC) is estab ...
- [UVA315]Network(tarjan, 求割点)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 无向连通图求割点(tarjan算法去掉改割点剩下的联通分量数目)
poj2117 Electricity Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3603 Accepted: 12 ...
- (转)Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)
基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成多个 ...
- uva 315 Network(无向图求割点)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 【UVA10765】Doves and bombs (BCC求割点后联通块数量)
题目: 题意: 给了一个联通无向图,现在问去掉某个点,会让图变成几个联通块? 输出的按分出的从多到小,若相等,输出标号从小到大.输出M个. 分析: BCC求割点后联通块数量,Tarjan算法. 联通块 ...
- UVA315 Network —— 割点
题目链接:https://vjudge.net/problem/UVA-315 A Telephone Line Company (TLC) is establishing a new telepho ...
随机推荐
- Cppcheck 1.54 C/C++静态代码分析工具
Cppcheck是一个C/C++代码分析工具,只检测那些编译器通常无法检测到的bug类型. 官方上建议让编译器提供尽量多的警告提示:1.使用Visual C++的话,应使用警告等级4 2.使用GC ...
- 强大的Http监控工具Fidder
软件下载:http://fiddler2.com/get-fiddler 软件学习:http://www.cnblogs.com/TankXiao/archive/2012/02/06/2337728 ...
- 【剑指offer】树的子结构
转载请注明出处:http://blog.csdn.net/ns_code/article/details/25907685 剑指offer第18题,九度OJ上測试通过! 题目描写叙述: 输入两颗二叉树 ...
- 关于android的nfc问题
最近在研究android的nfc问题 首先再网上有很多关于android nfc 读写的问题,但是大多数都是关于Mifare Classic类型卡的读写,我百试不得骑解,于是自己写了一些程序供大家参考 ...
- baas & API 网关
最近一段时间一直在做API 网关的工作.清晰看到当前云下Baas将会是主要方向,而API网关会是一把利剑. 本人正在规划API网关,有兴趣的可以一起探讨:hotwheels_bo@163.com
- 【Demo 0007】Android 信使(Intent)
本章学习要点: 1. 了解Intent功能作用: 2. 掌握Intent在显示和隐示基本使用方法及规则:
- Stripe
Description Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In eac ...
- 几个前端博客 good
http://www.cnblogs.com/JustinYoung/archive/2011/02/24/fresh-free-html-templates-2010.html http://www ...
- delphi实现图象灰度处理的3种方法
灰度处理的方法主要有如下3种: 1.最大值法:使R.G.B的值等于3值中最大的一个,即: R=G=B=max(R,G,B) 最大值法会使形成高亮度很高的灰度图象 var bitmap:tbitma ...
- autotools入门笔记(一)
GNU autotools作用:收集系统配置信息并自动生成Makefile文件. GNU autotools主要包括三个工具:autoconf.automake.libtool,还有很多辅助的工具,包 ...