割点的概念:对于无向图,删除这个点与其相连的边,整个图的连通分量个数增加。

对于无向图的tarjan算法,必须要设前驱~

求割点的模板~

#include<cstdio>
#include<algorithm>
#include<vector>
#include<stack>
#include<cstring>
using namespace std;
const int maxn=;
vector<int> g[maxn];
int N,M,x,y;
int low[maxn];
int dfn[maxn];
int cnt;
int scc;
int pos[maxn];
int isGedian[maxn];
int isRoot[maxn];
stack<int> st;
void init () {
fill (low,low+maxn,);
fill (dfn,dfn+maxn,);
fill (pos,pos+maxn,);
fill (isGedian,isGedian+maxn,);
for (int i=;i<maxn;i++) g[i].clear();
while (!st.empty()) st.pop();
cnt=;
scc=;
}
void tarjan (int x,int pre) {
low[x]=dfn[x]=++cnt;
int son=;
st.push(x);
for (int i=;i<g[x].size();i++) {
if (g[x][i]==pre) continue;
if (!low[g[x][i]]) {
son++;
tarjan(g[x][i],x);
low[x]=min(low[x],low[g[x][i]]);
if (x!=pre&&dfn[x]<=low[g[x][i]]) isGedian[x]=;
}
else if (!pos[g[x][i]]) low[x]=min(low[x],dfn[g[x][i]]);
}
if (low[x]==dfn[x]) {
scc++;
while () {
int u=st.top();
st.pop();
low[u]=low[x];
pos[u]=scc;
if (u==x) break;
}
}
if (x==pre&&son>) isGedian[x]=;
}
int main () {
while (scanf("%d",&N)&&N) {
init ();
while (scanf("%d",&x)&&x) {
char ch;
while ((ch=getchar())!='\n') {
scanf ("%d",&y);
g[x].push_back(y);
g[y].push_back(x);
}
}
for (int i=;i<=N;i++)
if (!low[i]) tarjan(i,i);
int gedian=;
for (int i=;i<=N;i++)
if (isGedian[i]) gedian++;
printf ("%d\n",gedian);
}
return ;
}

UVA315 Network的更多相关文章

  1. uva-315.network(连通图的割点)

    本题大意:求一个无向图额割点的个数. 本题思路:建图之后打一遍模板. /**************************************************************** ...

  2. UVA315 Network —— 割点

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

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

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

  4. UVA315 Network 连通图割点

    题目大意:有向图求割点 题目思路: 一个点u为割点时当且仅当满足两个两个条件之一: 1.该点为根节点且至少有两个子节点 2.u不为树根,且满足存在(u,v)为树枝边(或称 父子边,即u为v在搜索树中的 ...

  5. 连通图(Tarjan算法) 专题总结

    一.题目类型: 1.有向图的强连通分量: POJ1236 Network of Schools HDU1269 迷宫城堡 2.割点 & 割边: UESTC - 900 方老师炸弹 UVA315 ...

  6. UVA315:Network(求割点)

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

  7. Network -UVa315(连通图求割点)

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

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

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

  9. Recurrent Neural Network系列1--RNN(循环神经网络)概述

    作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 本文翻译自 RECURRENT NEURAL NETWORKS T ...

随机推荐

  1. MySQL数据库、数据表和字段字符集查询、修改和配置

    一.设置编码 LINUX  修改vi/etc/my.cnf WINDOWS my.ini 在[client]下添加    default-character-set=utf8 在[mysqld]下添加 ...

  2. 这是一篇通过open live writer发布的博文

    这两天零零总总的尝试了两三款写博客的软件,总感觉不怎么上手,最后还是使用博客园官方推荐的工具写博吧,简单方便,目前的功能基本都有,尤其是粘贴图片特别方便,回想之前的几篇博文,真是一种煎熬哈哈(对于我这 ...

  3. Apache Kafka(十)Partitions与Replication Factor 调整准则

    Partitions与Replication Factor调整准则 Partition 数目与Replication Factor是在创建一个topic时非常重要的两个参数,这两个参数的取值会直接影响 ...

  4. webpack配置的说明

    {devtool: 'source-map',//要启用source-map需加上此配置项,同时css或less的loader要加上参数?sourceMap,js的loader不用加 entry: e ...

  5. 浅谈ABB机器人(工具坐标,工件坐标,有效载荷)

    工具坐标(tool): 使tcl坐标偏移到工具上,例如焊接工作,使机器人工作点切入焊枪点上 mass:工具的重量 xyz:偏移距离的大小 验证:通过手动模式,切换至自定义工具,重定向 工件坐标(wob ...

  6. BLUE引擎检查放入装备的名称全名脚本

    格式:CHECKDLGITEMNAME 名称 检查条件需要配合QUERYITEMDLG命令 ;========================================== [@main]#AC ...

  7. Unity小知识点大全(一)

    原帖地址:https://zhuanlan.zhihu.com/p/54763553 1. 高亮选择 在Scene面板右上角的Gizmo下拉列表中,可以通过设置Selection Outline选项决 ...

  8. 973. 最接近原点的 K 个点

    1.暴力排序,新建节点类重载小于符号排序. class Solution { public: struct comb{ int index,distance; comb():index(0),dist ...

  9. 在MyEclipse2017中配置JDK和Tomcat8.5

    在MyEclipse2017中配置Tomcat8.5: 首先,确保你已安装好JDK.Tomcat等 1.启动MyEclipse后,点击菜单栏的"Window": 2.为MyEcli ...

  10. Go非缓冲/缓冲/双向/单向通道

    1. 非缓冲和缓冲 package main import ( "fmt" "strconv" ) func main() { /* 非缓冲通道:make(ch ...