题目链接:传送门

题目大意:一副无向图,问有多少个节点满足删除该节点后图不连通,对于每个满足条件的节点,输出节点编号及删除节点将图分为几个连通块。若没有节点满足则输出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)的更多相关文章

  1. POJ1523 SPF[无向图割点]

    SPF Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8139   Accepted: 3723 Description C ...

  2. 【POJ 1523】SPF(割点)

    儿子数大于1的树根或者 Low[v] >= DFN[u]的非树根节点v 就是割点. #include <cstdio> #include <cstring> const ...

  3. 自动SPF生成工具

    到openspf网站去自动生成一下,地址是http://old.openspf.org/wizard.html.详细解释见下图关于spf的详细语法请看http://www.openspf.org/SP ...

  4. SPF 简介

    SPF 简介 摘要: SPF 是发送方策略框架 (Sender Policy Framework) 的缩写,希望能成为一个防伪标准,来防止伪造邮件地址.这篇文章对 SPF 进行了简单介绍,并介绍了它的 ...

  5. POJ1523 SPF

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8254   Accepted: 3772 Description Consi ...

  6. POJ 1523 SPF tarjan求割点

                                                                   SPF Time Limit: 1000MS   Memory Limit ...

  7. POJ1523 SPF(割点模板)

    题目求一个无向图的所有割点,并输出删除这些割点后形成几个连通分量.用Tarjan算法: 一遍DFS,构造出一颗深度优先生成树,在原无向图中边分成了两种:树边(生成树上的边)和反祖边(非生成树上的边). ...

  8. POJ 1523 SPF(寻找关节点)

                                                                         SPF Time Limit: 1000MS   Memory ...

  9. 如何设置DNS的SPF记录

    如何设置DNS的SPF记录 Introduction SPF的完整意思为 "Sender Policy Framework".翻译过来就是发送方策略框架,是一项跟 DNS 相关的技 ...

随机推荐

  1. 微信小程序 - 文字走马灯

    转载于csdn maid_04,总之多谢了!节省了不少时间呢 最近在做一个类似uu跑腿的项目,时间也特别紧,搞完以后再继续贴地图代码(高德.腾讯) 以下代码拷贝即可用,拿走谢谢上面的人吧(~.~) w ...

  2. 怎样用Google APIs和Google的应用系统进行集成(4)----获得Access Token以通过一些Google APIs的OAuth2认证

    在上篇文章中: "怎样用Google APIs和Google的应用系统进行集成(3)----调用发现Google APIs的RESTful的服务"一文中,我们直接用jdk的java ...

  3. mysql cmd连接 乱码

    cmd 默认编码方式是gbk,而我的mysql 设置的编码方式是utf-8的:因此在cmd 中执行 mysql> set names gbk;再查询,发现cmd 中乱码问题得到了解决.

  4. atitit.MyEclipse10 中添加svn插件故障排除

    atitit.MyEclipse10 中添加svn插件故障排除 删除\configuration \org.eclipse.update 不行... 二. 在configuration下的config ...

  5. linux 单机跨进程通信

    一般来说通过网络通信(比如tcp,udp)或者共享内存的方式肯定可以实现跨进程通信,但现在这里要说的是比较偏但实用的几个方法:利用unix域通信(普通网络连接),利用unix域通信(socketpai ...

  6. Python课程之字典

    字典(dict) 一.定义:字典类型在其他语言中又称为map,是一种映射类型,并且{key:value}无序,其关键字必须为不可变类型(如:元组/字符串),在同一个字典中关键字必须互不相同(若出现相同 ...

  7. Hive 练习 简单任务处理

    1.2018年4月份的用户数.订单量.销量.GMV (不局限与这些统计量,你也可以自己想一些) -- -- -- 2018年4月份的用户数量 select count(a.user_id) as us ...

  8. Nginx负载均衡和LVS负载均衡的比较分析(转)

    Nginx负载均衡和LVS负载均衡的比较分析 作者:匿名 来源:ChinaZ源码报导 浏览:1032次 2011-12-6 15:12:27 字号:大 中 小 [摘要]Nginx是一个高性能的 HTT ...

  9. MVC Controller return 格式之JsonResult、ContentResult、RedirectResult……

      //语法 public class JsonResult : ActionResult public class ContentResult : ActionResult public class ...

  10. 如何將 MySQL 資料庫轉移到 Microsoft SQL Server 與 Azure SQL Database

    MySQL 是相當常用之資料庫伺服器,而微軟雲端服務 Microsoft Azure 上 Azure SQL Database 是一個功能強大且經濟實惠的選擇,透過本篇文章,使用 SQL Server ...