ZOJ1119(SPF)
题目链接:传送门
题目大意:一副无向图,问有多少个节点满足删除该节点后图不连通,对于每个满足条件的节点,输出节点编号及删除节点将图分为几个连通块。若没有节点满足则输出No SPF nodes
题目思路:tarjan算法求关节点入门题(也可用矩阵存图)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
#define Min(x,y) (x<y?x:y)
#define Max(x,y) (x>y?x:y)
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 100000007
#define inf 0x3f3f3f3f
#define N 1000005
#define maxn 1000050
typedef long long LL;
typedef pair<int,int> PII; int n,m,head[],hcnt,son,num;
int dfn[],low[],area[],vis[];
int deep;
struct Node{
int to,next;
Node(){}
Node(int a,int b):to(a),next(b){}
}node[];
inline void add(int x,int y){
node[hcnt]=Node(y,head[x]);
head[x]=hcnt++;
} void init(){
num=; ///最大节点的编号
hcnt=;
deep=; ///深度搜索树的深度优先数(第几个被搜索)
son=; ///记录根节点的子女个数
low[]=dfn[]=; ///low表示节点能通过子女和回边到达的最小深度优先数
mst(head,-); ///dfn表示节点的深度优先数
mst(vis,);
mst(area,); ///记录删除某个节点后图被分成了几块
vis[]=; ///标记节点是否访问过
} void dfs(int x){
for(int i=head[x];~i;i=node[i].next){
int e=node[i].to;
if(vis[e]) low[x]=Min(low[x],dfn[e]);
else{
vis[e]=;
dfn[e]=low[e]=++deep;
dfs(e);
low[x]=Min(low[x],low[e]);
if(low[e]>=dfn[x]){
if(x==) ++son;
else ++area[x];
}
}
}
} int main(){
int i,j,group,Case=,x,y;
while(scanf("%d",&x)!=EOF&&x){
init();
num=Max(num,x);
scanf("%d",&y);
num=Max(num,y);
add(x,y);
add(y,x);
while(scanf("%d",&x)&&x){
num=Max(num,x);
scanf("%d",&y);
num=Max(num,y);
add(x,y);
add(y,x);
}
if(Case)printf("\n");
printf("Network #%d\n",++Case);
dfs();
if(son>)area[]=son-;
int flag=;
for(i=;i<=num;++i)if(area[i]){
flag=;
printf(" SPF node %d leaves %d subnets\n",i,area[i]+);
}
if(!flag) printf(" No SPF nodes\n");
}
return ;
}
ZOJ1119(SPF)的更多相关文章
- POJ1523 SPF[无向图割点]
SPF Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8139 Accepted: 3723 Description C ...
- 【POJ 1523】SPF(割点)
儿子数大于1的树根或者 Low[v] >= DFN[u]的非树根节点v 就是割点. #include <cstdio> #include <cstring> const ...
- 自动SPF生成工具
到openspf网站去自动生成一下,地址是http://old.openspf.org/wizard.html.详细解释见下图关于spf的详细语法请看http://www.openspf.org/SP ...
- SPF 简介
SPF 简介 摘要: SPF 是发送方策略框架 (Sender Policy Framework) 的缩写,希望能成为一个防伪标准,来防止伪造邮件地址.这篇文章对 SPF 进行了简单介绍,并介绍了它的 ...
- POJ1523 SPF
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8254 Accepted: 3772 Description Consi ...
- POJ 1523 SPF tarjan求割点
SPF Time Limit: 1000MS Memory Limit ...
- POJ1523 SPF(割点模板)
题目求一个无向图的所有割点,并输出删除这些割点后形成几个连通分量.用Tarjan算法: 一遍DFS,构造出一颗深度优先生成树,在原无向图中边分成了两种:树边(生成树上的边)和反祖边(非生成树上的边). ...
- POJ 1523 SPF(寻找关节点)
SPF Time Limit: 1000MS Memory ...
- 如何设置DNS的SPF记录
如何设置DNS的SPF记录 Introduction SPF的完整意思为 "Sender Policy Framework".翻译过来就是发送方策略框架,是一项跟 DNS 相关的技 ...
随机推荐
- Java中Vector与ArrayList的差别具体解释
首先看这两类都实现List接口,而List接口一共同拥有三个实现类.各自是ArrayList.Vector和LinkedList.List用于存放多个元素,可以维护元素的次序,而且同意元素的反复. 3 ...
- 在 XenServer上调试windows程序
WinDbg WinDbg is one of a number of tools available from Microsoft that can be used for debugging Wi ...
- ViewPager中Fragment无法显示的问题
问题描述: Actvitiy->Fragment1 ->Fragment2 Fragment1中有1个ViewPager,ViewPager里面有包括了2个Fragment. 当第一次执行 ...
- atitit.MyEclipse10 中添加svn插件故障排除
atitit.MyEclipse10 中添加svn插件故障排除 删除\configuration \org.eclipse.update 不行... 二. 在configuration下的config ...
- spring中反射机制和注入的使用
http://www.cnblogs.com/andin/archive/2011/04/30/spring.html spring的一大核心概念是注入, 但是,这存在的一个前提就是类是由spring ...
- chrome扩展(浏览器插件)开发实用教程
原创文章,转载请注明出处. 作者:简体字丶冯; QQ:564372931 1.Chrome能搞这些事情 (1) 操作浏览器中打开的页面DOM 这能做什么哪?譬如说你想修改页面DOM(DOM是什 ...
- Java线程安全同步容器
线程安全同步容器(使用 synchronized关键字) 1.ArrayList->Vector,Stack 2.HashMap->HashTable(key.value不能为null) ...
- python剑指网络篇二
在socket编程中 AF_INET 对应 IPv4 SOCK_STREAM 对应 TCP SOCK_DGRAM 对应 UDP
- vue的计算属性
在模板中写入过多的逻辑使模板过重且难以维护.因此有了计算属性(computed)的产生. 你可以像绑定普通属性一样在模板中绑定计算属性,vue知道计算属性中的函数依赖data中的数据.所以当data中 ...
- SparseArray具体解释,我说SparseArray,你说要!
可能在Android 中使用HashMap 的时候看到过提示. HashMap<Integer,Bitmap> mp = new HashMap<Integer,Bitmap> ...