1123: [POI2008]BLO

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 1030  Solved: 440
[Submit][Status][Discuss]

Description

Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通。

Input

输入n<=100000 m<=500000及m条边

Output

输出n个数,代表如果把第i个点去掉,将有多少对点不能互通。

Sample Input

5 5
1 2
2 3
1 3
3 4
4 5

Sample Output

8
8
16
14
8

HINT

 

Source

 

[Submit][Status][Discuss]

分析

如果一个点不是割点,那么删去后不会对其他点之间的连通性造成影响;如果是一个割点,影响只和其连接的几个块的大小有关。因此Tarjan求割点的同时注意维护子树大小即可。

代码

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm> using namespace std; #define N 5000000
#define LL long long int n, m; LL ans[N]; int hd[N], to[N], nt[N], tot; int dfn[N], low[N], tim; int tarjan(int u, int f)
{
dfn[u] = low[u] = ++tim; ans[u] = (n - ) << ; int cnt = , siz; LL sum = , tmp = ; for (int i = hd[u]; ~i; i = nt[i])if (f != to[i])
{
if (!dfn[to[i]])
{
siz = tarjan(to[i], u);
low[u] = min(low[u], low[to[i]]);
if (low[to[i]] >= dfn[u])
ans[u] += 2LL * siz * sum, sum += siz;
else
tmp += siz;
}
else
low[u] = min(low[u], dfn[to[i]]);
} ans[u] += 2LL * (n - (sum + )) * sum; return sum + tmp + ;
} signed main(void)
{
scanf("%d%d", &n, &m); memset(hd, -, sizeof(hd)), tot = ; for (int i = ; i <= m; ++i)
{
int x, y; scanf("%d%d", &x, &y); nt[tot] = hd[x]; to[tot] = y; hd[x] = tot++;
nt[tot] = hd[y]; to[tot] = x; hd[y] = tot++;
} memset(dfn, , sizeof(dfn)); tim = ; tarjan(, -); for (int i = ; i <= n; ++i)
printf("%lld\n", ans[i]);
}

BZOJ_1123.cpp

 #include <cstdio>

 template <class T>
inline T min(const T &a, const T &b)
{
return a < b ? a : b;
} typedef long long lnt; const int mxn = ;
const int mxm = ; int n, m; int hd[mxn];
int to[mxm];
int nt[mxm]; int dfn[mxn];
int low[mxn]; lnt ans[mxn]; lnt tarjan(int u, int f)
{
static int tim = ; ans[u] = (n - ) << ;
dfn[u] = low[u] = ++tim; lnt siz, sum = , tmp = ; for (int i = hd[u], v; i; i = nt[i])
if ((v = to[i]) != f)
{
if (!dfn[v])
{
siz = tarjan(v, u); low[u] = min(low[u], low[v]); if (low[v] >= dfn[u])
ans[u] += 2LL * sum * siz, sum += siz;
else
tmp += siz;
}
else
low[u] = min(low[u], dfn[v]);
} ans[u] += 2LL * (n - sum - ) * sum; return sum + tmp + ;
} signed main(void)
{
scanf("%d%d", &n, &m); for (int i = ; i < m; ++i)
{
static int x, y, tot; scanf("%d%d", &x, &y); nt[++tot] = hd[x], to[tot] = y, hd[x] = tot;
nt[++tot] = hd[y], to[tot] = x, hd[y] = tot;
} tarjan(, ); for (int i = ; i <= n; ++i)
printf("%lld\n", ans[i]);
}

@Author: YouSiki

BZOJ 1123: [POI2008]BLO的更多相关文章

  1. BZOJ 1123: [POI2008]BLO( tarjan )

    tarjan找割点..不是割点答案就是(N-1)*2, 是割点的话就在tarjan的时候顺便统计一下 ------------------------------------------------- ...

  2. bzoj 1123 [POI2008]BLO Tarjan求割点

    [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1540  Solved: 711[Submit][Status][Discu ...

  3. BZOJ 1123 [POI2008]BLO(Tarjan算法)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1123 [题目大意] Byteotia城市有n个towns,m条双向roads. 每条r ...

  4. bzoj 1123 [POI2008]BLO——点双连通分量

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1123 点双连通分量缩点,然后各种各样. 结果不会写了.比如新连边.记录一个点是割点缩成的点还 ...

  5. BZOJ 1123: [POI2008]BLO 求割点_乘法原理_计数

    Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通. Input 输入n&l ...

  6. BZOJ1123: [POI2008]BLO

    1123: [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 614  Solved: 235[Submit][Status] ...

  7. Bzoj 1131[POI2008]STA-Station (树形DP)

    Bzoj 1131[POI2008]STA-Station (树形DP) 状态: 设\(f[i]\)为以\(i\)为根的深度之和,然后考虑从他父亲转移. 发现儿子的深度及其自己的深度\(-1\) 其余 ...

  8. [POI2008]BLO(Tarjan)

    [POI2008]BLO Description Byteotia城市有\(n\)个 towns \(m\)条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所 ...

  9. BZOJ 1123 BLO

    tarjan求割点计算答案.注意不是每一棵子树都算答案.开个变量记一下. #include<iostream> #include<cstdio> #include<cst ...

随机推荐

  1. Docker容器概念讲解

    Docker 是 PaaS 提供商 dotCloud 开源的一个基于 LXC 的高级容器引擎,源代码托管在 Github 上, 基于go语言并遵从Apache2.0协议开源. Docker是通过内核虚 ...

  2. ajax异步举例

    SelectInfo = { release_url: "/compatible/getReleaseFor", project_url: "/compatible/ge ...

  3. javascript判断手机旋转横屏竖屏

    javascript判断手机旋转横屏竖屏 // 横屏竖屏函数 function orientationChange(){ switch(window.orientation) { case 0: // ...

  4. Html5 Egret游戏开发 成语大挑战(一)开篇

    最近接触了Egret白鹭引擎,感觉非常好用,提供了各种各样的开发工具让开发者和设计者更加便捷,并且基于typescript语言开发省去了很多学习成本,对于我们这种掉微软坑许久的童鞋来说,确实很有吸引力 ...

  5. Visual Studio 2012 cannot identify IHttpActionResult

    使用ASP.NET Web API构造基于restful风格web services,IHttpActionResult是一个很好的http结果返回接口. 然而发现在vs2012开发环境中,Syste ...

  6. 博客搬家。新博客地址 http://fangjian0423.github.io/

    以后新的博客会发到 http://fangjian0423.github.io/ 里. 这里基本上不会再更新博客了.

  7. Tomcat 项目部署方式

    方法一:在Tomcat中的Conf目录中,在Server.Xml中的,<Host/>节点中添加: <Context Path="/Hello"Docbase=&q ...

  8. opencv2-新特性及Mat

    本文参照<opencv_2.4.9tutorial>的core部分完成.因为功力还不足以学习侯捷那种大师一样去深入浅出的解析opencv的源码,也只能先学会怎么用opencv,然后实在觉得 ...

  9. 我的Logo设计简史

    近日,日本东京奥运会会微因涉嫌抄袭而被弃用的新闻引起设计界的一翻热论.在此我想到自己的LOGO设计,虽说并一定不好看甚至自己看回来都觉得略丑,但 几乎没有过抄袭的念头.有句话说,不想当设计师的程序猿不 ...

  10. hbase-site.xml 配置详解

    hbase.rootdir 这个目录是region server的共享目录,用来持久化HBase.URL需要是'完全正确'的,还要包含文件系统的scheme.例如,要表示hdfs中的'/hbase'目 ...