题目要求割顶集,并且还要求出去掉割顶之后剩下的图连通数目。

tarjan算法求出割顶后直接枚举就可以了吧。

一开始想到利用iscut[u]的次数也就是点u被判定为割顶的次数求连通分量数,还有利用与结点u相连的点的bccno不同的编号来判定,都是不行的,具体原因自己想清楚比较好。

以后就不会犯这样的错误了。

代码:

#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <string>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define pi acos(-1.0)
#define pb push_back
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define mp(a, b) make_pair((a), (b))
#define in freopen("in.txt", "r", stdin);
#define out freopen("out.txt", "w", stdout);
#define print(a) printf("%d\n",(a));
#define bug puts("********))))))");
#define stop system("pause");
#define Rep(i, c) for(__typeof(c.end()) i = c.begin(); i != c.end(); i++)
#define inf 0x0f0f0f0f using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii,int> VII;
typedef vector<int>:: iterator IT; const int maxn = ;
int pre[maxn], iscut[maxn], vis[maxn], low[maxn], bccno[maxn], dfs_clock, bcc_cnt;
VI g[maxn], bcc[maxn];
int flag;
struct edge
{
int u, v;
edge(int u, int v):u(u), v(v) {}
};
stack<edge> S;
int dfs(int u, int fa)
{
int lowu = pre[u] = ++dfs_clock;
int child = ;
for(int i = ; i < g[u].size(); i++)
{
int v = g[u][i];
edge e = edge(u, v);
if(!pre[v])
{
S.push(e);
child++;
int lowv = dfs(v, u);
lowu = min(lowu, lowv);
if(lowv >= pre[u])
{
bcc_cnt++;
bcc[bcc_cnt].clear();
iscut[u] = ;
for(;;)
{
edge x = S.top();
S.pop();
if(bccno[x.u] != bcc_cnt)
{
bccno[x.u] = bcc_cnt;
bcc[bcc_cnt].pb(x.u);
}
if(bccno[x.v] != bcc_cnt)
{
bccno[x.v] = bcc_cnt;
bcc[bcc_cnt].pb(x.v);
}
if(x.u == u && x.v == v) break;
}
}
}
else if(pre[v] < pre[u] && v != fa)
{
S.push(e);
lowu = min(lowu, pre[v]);
}
}
if(child == && fa < )
{
iscut[u] = ;
}
return low[u] = lowu;
} void find_bcc(int n)
{
memset(pre, , sizeof(pre));
memset(iscut, , sizeof(iscut));
memset(bccno, , sizeof(bccno)); dfs_clock = bcc_cnt = ;
for(int i = ; i <= n; i++)
if(!pre[i])
dfs(i, -);
}
void dfs1(int u)
{
vis[u] = ;
for(int i = ; i < g[u].size(); i++)
{
int v = g[u][i];
if(!vis[v])
{
dfs1(v);
}
}
}
void init(void)
{
for(int i = ; i < maxn; i++)
g[i].clear();
}
int main(void)
{
int n;
int u, v;
int t = ;
while(scanf("%d", &u), u)
{
init();
flag = ;
n = ;
scanf("%d", &v);
g[u].pb(v);
g[v].pb(u);
n = max(max(u, v), n);
while(scanf("%d", &u), u)
{
scanf("%d", &v);
g[u].pb(v);
g[v].pb(u);
n = max(max(u, v), n);
}
find_bcc(n);
if(t) puts("");
t++;
printf("Network #%d\n", t);
for(int u = ; u <= ; u++)
if(iscut[u])
{
flag = ;
memset(vis, , sizeof(vis));
int cnt = ;
vis[u] = ;
for(int i = ; i < g[u].size(); i++)
{
int v = g[u][i];
if(!vis[v])
cnt++, dfs1(v);
}
printf(" SPF node %d leaves %d subnets\n", u, cnt);
}
if(!flag)
{
puts(" No SPF nodes");
}
}
return ;
}

POJ - 1523 SPF的更多相关文章

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

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

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

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

  3. POJ 1523 SPF tarjan求割点

                                                                   SPF Time Limit: 1000MS   Memory Limit ...

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

                                                                         SPF Time Limit: 1000MS   Memory ...

  5. POJ 1523 SPF(求割点)

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

  6. POJ 1523 SPF (割点,连通分量)

    题意:给出一个网络(不一定连通),求所有的割点,以及割点可以切分出多少个连通分量. 思路:很多种情况. (1)如果给的图已经不是连通图,直接“  No SPF nodes”. (2)求所有割点应该不难 ...

  7. zoj 1119 /poj 1523 SPF

    题目描述:考虑图8.9中的两个网络,假定网络中的数据只在有线路直接连接的2个结点之间以点对点的方式传输.一个结点出现故障,比如图(a)所示的网络中结点3出现故障,将会阻止其他某些结点之间的通信.结点1 ...

  8. poj 1523 SPF【点双连通求去掉割点后bcc个数】

    SPF Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7246   Accepted: 3302 Description C ...

  9. POJ 1523 SPF (去掉割点能形成联通块的个数)

    思路:使用tarjan算法求出割点,在枚举去掉每一个割点所能形成的联通块的个数. 注意:后来我看了下别的代码,发现我的枚举割点的方式是比较蠢的方式,我们完全可以在tarjan过程中把答案求出来,引入一 ...

随机推荐

  1. jQuery Easy UI 使用

    一.引入必要文件 二.加载UI组件的方式 加载 UI 组件有两种方式: 1.使用 class 方式加载: 2.使用 JS 调用加载.//使用 class 加载,格式为: easyui-组件名 效果: ...

  2. ora 32021 设置参数时参数值长度超过255处理办法

    alter system set db_file_name_convert='AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA-.' scope=spfi ...

  3. android体系架构

    android体系架构总结: android体系架构分为四层 第一层:应用层:applications 第二层:开发层 第三层:

  4. PHPEXCEL使用实例

    最近在项目中要用到PHP生成EXCEL,上网找了一下,发现PHPEXCEL挺不错,用了一下,感觉还行,就是设置单元格格式的时候比较麻烦,总体来说功能还是比较强大的,还有生成PDF什么的,发一个实例吧 ...

  5. linux下python导出sybase 数据库 表记录的方式

    导出sybase 数据库 表记录的方式 1 执行启动sybase 数据库命令 code : dbeng7 gkdb 2 执行 连接sybase 数据库命令code : dbisql -c " ...

  6. MEF学习笔记

    之前公司里用到了一个叫MEF的东西,说来惭愧一直只管写代码却不曾理解MEF框架为何物,今天就来学习一下,这是一篇迟到了不知多久的博客. -------------------------------- ...

  7. [JQuery]选择器详解

      示例 说明 $(this) 当前元素 $("p") 所有<p>元素 $("input") 所有input元素 $(".intro&qu ...

  8. Live帐号登陆win8系统不用输密码的方法

    win 8 系统旨在让大家日常的操作更加方便与快捷.因此,今天,小编将与大家分享的是如何利用Live帐号登陆win8系统,而不用输密码的方法.具体的步骤如下文所述. 按win+R打开运行输入cmd(在 ...

  9. CentOS添加RPMforge软件源

    1.查看CentOS版本 cat /etc/redhat-release 2.查看系统位数 uname -i 3.下载rpm包 wget "rpm地址" CentOS 6: i68 ...

  10. VM启动报错:Failed to lock the file

    http://www.cnblogs.com/kristain/articles/2491966.html Reason: Failed to lock the fileGoogle 了一下, 在網路 ...