UVA315 Network
割点的概念:对于无向图,删除这个点与其相连的边,整个图的连通分量个数增加。
对于无向图的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的更多相关文章
- uva-315.network(连通图的割点)
本题大意:求一个无向图额割点的个数. 本题思路:建图之后打一遍模板. /**************************************************************** ...
- UVA315 Network —— 割点
题目链接:https://vjudge.net/problem/UVA-315 A Telephone Line Company (TLC) is establishing a new telepho ...
- [UVA315]Network(tarjan, 求割点)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA315 Network 连通图割点
题目大意:有向图求割点 题目思路: 一个点u为割点时当且仅当满足两个两个条件之一: 1.该点为根节点且至少有两个子节点 2.u不为树根,且满足存在(u,v)为树枝边(或称 父子边,即u为v在搜索树中的 ...
- 连通图(Tarjan算法) 专题总结
一.题目类型: 1.有向图的强连通分量: POJ1236 Network of Schools HDU1269 迷宫城堡 2.割点 & 割边: UESTC - 900 方老师炸弹 UVA315 ...
- UVA315:Network(求割点)
Network 题目链接:https://vjudge.net/problem/UVA-315 Description: A Telephone Line Company (TLC) is estab ...
- Network -UVa315(连通图求割点)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=sh ...
- (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Recurrent Neural Network系列1--RNN(循环神经网络)概述
作者:zhbzz2007 出处:http://www.cnblogs.com/zhbzz2007 欢迎转载,也请保留这段声明.谢谢! 本文翻译自 RECURRENT NEURAL NETWORKS T ...
随机推荐
- wireshark抓pc上的包
简介:wirkshark是全世界最广泛的网络封包分析软件之一. 软件用途: 网络管理员:我用它检测网络问题, 网络安全工程师:我用它检查资讯安全相关问题, 开发者:我用它为新的通讯协定除错, 普通使用 ...
- CentOS之service iptables stop 显示not loaded
停止firewalld服务停止防火墙,并禁用这个服务 sudo systemctl stop firewalld.servicesudo systemctl disable firewalld.ser ...
- Goahead WebSever 总结
编译成功后用http://127.0.0.1可以访问网站,若端口号不是默认的80,者访问时加“:端口”,如: http://127.0.0.1:8888 1.websHomePageHandler函数 ...
- Strategic game树形DP解法(Poj1463,Uva1292)
已经写过本题用二分图的做法,见这儿. 本题的图是一棵树,求最小点覆盖也可以用树形DP的做法. 定义状态f[0/1][u]表示以u为根的子树,u选取/不选最少需要选取多少点来覆盖. 显然 f[0][u] ...
- C语言 strlen
C语言 strlen #include <string.h> size_t strlen(const char *s); 功能:计算指定指定字符串s的长度,不包含字符串结束符‘\0’ 参数 ...
- RTMP服务器搭建(nginx+rtmp)
参考文章:https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.5 ...
- UVA 11520 Fill the Square(模拟)
题目链接:https://vjudge.net/problem/UVA-11520 这道题我们发现$n\leq 10$,所以直接进行暴力枚举. 因为根据字典序所以每个位置试一下即可,这样的复杂度不过也 ...
- 前端分页神器,jquery grid的使用(前后端联调),让分页变得更简单。
jquery grid 是一款非常好用的前端分页插件,下面来讲讲怎么使用. 首先需要引入jquery grid 的CSS和JS (我们使用的是bootstrap的样式) 下面我们通过一个例子来讲解,需 ...
- C#常用的form窗体属性(最大化、最小化、窗体居中)
一.窗体居中 //窗体居中 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 二.去掉最小化.最大化 ...
- MongoDB C#驱动使用方法
string connStr = ConfigurationManager.ConnectionStrings["MongoDBConnStr"].ConnectionString ...