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

对于无向图的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. [lua]紫猫lua教程-命令宝典-L1-01-12. 临时补充2

    1.lua的环境变量和函数 (1)_G表  (个人习惯遍历下_G 看看当前环境支持什么库 很多库不是默认就支持的 需要按照流程导入或者加载) 一个全局变量(非函数),内部储存有当前所有的全局函数和全局 ...

  2. Go_CSP并发模型

    go语言的最大两个亮点,一个是goroutine,一个就是chan了.二者合体的典型应用CSP,基本就是大家认可的并行开发神器,简化了并行程序的开发难度,我们来看一下CSP. 11.1.CSP是什么 ...

  3. html滑动

    $('html, body').animate({scrollTop: 1500}, 'fast');

  4. python-PIL-16bit-灰度图像生成-tiff

    import numpy from PIL import Image a=numpy.array(numpy.uint16([[12,23,34],[123,213,22]])) im=Image.f ...

  5. 95. 不同的二叉搜索树 II、96. 不同的二叉搜索树

    95 Tg:递归 这题不能算DP吧,就是递归 一个问题:每次的树都要新建,不能共用一个根节点,否则下次遍历对根左右子树的改动会把已经放进结果数组中的树改掉.. class Solution: def ...

  6. js判断非127开头的IP地址

    js验证回送地址,IP地址不能以127开头 回送地址(127.x.x.x)是本机回送地址(Loopback Address) var ipNotStartWith127 = function(ip) ...

  7. redis常用配置参数

    首先弄清楚当前redis读取的是哪个配置文件,然后去配置文件修改,例如windows 打开服务列表,点击Redis,右键属性 "D:\Program Files\Redis\redis-se ...

  8. Blocked Billboard II

    前言 今天比赛真的状态不好(腐了一小会),导致差点爆0. 这个题解真的是在非常非常专注下写出来的,要不然真的心态崩. 刚换了域名,发现了美化脚本的bug,有点担心(汗-_-||). 题目 题目描述 奶 ...

  9. 普及C组第二题(8.5)

    1565. [GDKOI]神秘山庄 (Standard IO) 时间限制: 1000 ms  空间限制: 262144 KB 题目: 翠亨村是一个神秘的山庄,并不是因为它孕育了伟人孙中山,更神秘的是山 ...

  10. Java - 集合 - List

    1.List实现类:ArrayList.LinkedList.Vector ArrayList使用: void test() { //声明 List<String> testlist = ...