<题目链接>

题目大意:

给你一个连通的无向图,问你其中割点的编号,并且输出删除该割点后,原图会被分成几个连通分量。

解题分析:

Tarjan求割点模板题。

 #include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++)
#define clr(i,a) memset(i,a,sizeof(i))
const int N = ;
int head[N], cnt, rt, add_block[N], dfn[N], low[N], fa[N], tot;
struct Edge{
int to, next;
}e[N*N];
inline int read(){
int r=, f=; char c=getchar();
for(; c<''||c>''; c=getchar()) if(c=='-')f=-;
for(; c>=''&&c<=''; c=getchar()) r=r*+c-'';
return f*r;
}
void add(int u, int v) {
e[++cnt].next=head[u]; head[u]=cnt; e[cnt].to=v;
e[++cnt].next=head[v]; head[v]=cnt; e[cnt].to=u;
}
void tarjan(int u, int fa) {
dfn[u]=low[u]=++tot;
int child=;
for(int i=head[u];~i; i=e[i].next) {
int v=e[i].to;
if(!dfn[v]) {
tarjan(v, u);
++child;
if(low[v]>=dfn[u])++add_block[u]; //add_block代表删除u后能够增加的分量个数
low[u]=min(low[v], low[u]);
}
else if(dfn[v]<dfn[u] && fa!=v)low[u]=min(low[u], dfn[v]);
}
if(child== && fa==-) add_block[u]=; //如果
else if(child> && fa==-) add_block[u]=child-;
} int main() {
int u, v, ncase=;
while(true) {
u=read(); if(u==) break;
v=read();
clr(head, -); clr(add_block, ); cnt=tot=; clr(dfn, ); clr(low, );
add(u, v);rt=max(rt, v);
while() {
u=read(); if(u==) break;
v=read();
add(u, v); rt=max(rt, v); //rt用来记录序号最大的节点
}
rep(i, , rt) if(head[i]!=- && !dfn[i]) tarjan(i, -);
int flag=;
printf("Network #%d\n", ++ncase);
rep(i, , rt) if(add_block[i])
printf(" SPF node %d leaves %d subnets\n", i, add_block[i]+), flag=;
if(!flag) puts(" No SPF nodes");
puts("");
}
return ;
}

2018-12-02

POJ 1523 SPF (无向图割点)的更多相关文章

  1. poj 1523 SPF 无向图求割点

    SPF Description Consider the two networks shown below. Assuming that data moves around these network ...

  2. POJ 1523 SPF 求割点的好(板子)题!

    题意: 给个无向图,问有多少个割点,对于每个割点求删除这个点之后会产生多少新的点双联通分量 题还是很果的 怎么求割点请参考tarjan无向图 关于能产生几个新的双联通分量,对于每个节点u来说,我们判断 ...

  3. poj 1523 SPF 求割点以及删除该割点后联通块的数量

    SPF Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7136   Accepted: 3255 Description C ...

  4. zoj 1119 / poj 1523 SPF (典型例题 求割点 Tarjan 算法)

    poj : http://poj.org/problem?id=1523 如果无向图中一个点 u 为割点 则u 或者是具有两个及以上子女的深度优先生成树的根,或者虽然不是一个根,但是它有一个子女 w, ...

  5. poj 1523"SPF"(无向图求割点)

    传送门 题意: 有一张联通网络,求出所有的割点: 对于割点 u ,求将 u 删去后,此图有多少个联通子网络: 对于含有割点的,按升序输出: 题解: DFS求割点入门题,不会的戳这里

  6. poj 1523 SPF(双连通分量割点模板)

    题目链接:http://poj.org/problem?id=1523 题意:给出无向图的若干条边,求割点以及各个删掉其中一个割点后将图分为几块. 题目分析:割点用tarjan算法求出来,对于每个割点 ...

  7. 【POJ】1523 SPF(割点)

    http://poj.org/problem?id=1523 太弱... too weak.. 割点我都还要看书和看题解来写..果然是写不出么.. 割点就那样求,然后分量直接这个节点有多少子树就有子树 ...

  8. POJ 1523 SPF tarjan求割点

                                                                   SPF Time Limit: 1000MS   Memory Limit ...

  9. POJ 1523 SPF(求割点)

    题目链接 题意 : 找出图中所有的割点,然后输出删掉他们之后还剩多少个连通分量. 思路 : v与u邻接,要么v是u的孩子,要么u是v的祖先,(u,v)构成一条回边. //poj1523 #includ ...

随机推荐

  1. hibernate入门程序

    快速入门       1. 下载Hibernate框架的开发包       2. 编写数据库和表结构 Create database hibernate_day01; Use hibernate_da ...

  2. Oracle 口令文件:即 oracle密码文件

    一:文件路径位置 [oracle@localhost db_1]$ cd $ORACLE_HOME/dbs [oracle@localhost dbs]$ ls dbsorapwPROD1 hc_or ...

  3. Confluence 6 workbox 通知包含了什么

    当一个用户在 Confluence 中进行下面的操作的时候,workbox 将会显示为通知: 分享(Shares)你的页面或者博客页面. 提及(Mentions)你的页面,博客页面,回复或者任务. 你 ...

  4. Confluence 6 后台中为站点添加应用导航

    Confluence 6 后台中为站点添加应用导航的连界面和方法. https://www.cwiki.us/display/CONFLUENCEWIKI/Configuring+the+Site+H ...

  5. js操作数组元素

    一, 删除数组指定的某个元素 首先可以给JS的数组对象定义一个函数,用于查找指定的元素在数组中的位置,即索引,代码为: Array.prototype.indexOf = function(val) ...

  6. 用flask的扩展实现的简单的页面登录

    from flask import Flask,render_template,request,redirect,session app = Flask(__name__,template_folde ...

  7. Zookeeper客户端Curator的使用,简单高效

    Curator是Netflix公司开源的一个Zookeeper客户端,与Zookeeper提供的原生客户端相比,Curator的抽象层次更高,简化了Zookeeper客户端的开发量. 1.引入依赖: ...

  8. (不断更新)关于显著性检测的调研-Salient Object Detection: A Survey

    <Salient Object Detection: A Survey>作者:Ali Borji.Ming-Ming Cheng.Huaizu Jiang and Jia Li 基本按照文 ...

  9. rsync注意事项

    1.sudo rsync -zavP --exclude=/.git/ --exclude=.env --exclude=web/index.php  --password-file=/usr/loc ...

  10. AI-跨域、垃圾回收、content_type组见、接口处理

    AI-跨域.垃圾回收.content_type组见.接口处理 跨域 为什么有跨域?什么时候遇见的?答:由于浏览器的同源策略 阻止ajax请求 不阻止src请求:在测试时,项目上线后不会遇见跨域.源:协 ...