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

对于无向图的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. jmeter+ant+jenkins接口自动化测试框架

    大致思路:Jmeter可以做接口测试,也能做压力测试,而且是开源软件:Ant是基于Java的构建工具,完成脚本执行并收集结果生成报告,可以跨平台,Jenkins是持续集成工具.将这三者结合起来可以搭建 ...

  2. 洛谷P1118 [USACO06FEB]数字三角形`Backward Digit Su`…

    #include<iostream> using namespace std ; ; int y[N][N]; int n; int a[N]; bool st[N]; int sum; ...

  3. [Note]后缀自动机

    后缀自动机 代码 #include <cstdio> #include <algorithm> #include <cstring> const int M = 1 ...

  4. Pycharm调试django项目时发现断点失效

    解决方法: 第一步: 第二步: 点击 Edit Configuration 第三步 : 点击 + 选择python 填写相关参数信息 或者 点击ok  完成配置  重启 IDE 注意   重启IDE ...

  5. 使用java实现AES算法的加解密(亲测可用)

    话不多说,直接上代码 import javax.crypto.Cipher;   import javax.crypto.spec.IvParameterSpec; import javax.cryp ...

  6. 网络常识---tracert

    当打不开一个网页,可以是用如下命令查看请求的数据走到哪里了 在命令行中输入“tracert ”并在后面加入一个IP地址,可以查询从本机到该IP地址所在的电脑要经过的路由器及其IP地址

  7. 计算几何-Andrew法-凸包

    This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. 利用一下叉积和栈 ...

  8. Codeforces Round #598 (Div. 3) C. Platforms Jumping

    There is a river of width nn. The left bank of the river is cell 00 and the right bank is cell n+1n+ ...

  9. django-cors-headers

    django-cors-headers介绍 一个Django应用程序,向响应头中添加跨域资源共享(CORS)头.这允许从其他来源向Django应用程序发出浏览器内请求,当然也可以自定义中间件然后添加响 ...

  10. mybatis的8月29日

    一.select查询语句 1.mybatis的映射,jdbc预处理 <select id="selectPerson" parameterType="int&quo ...