BZOJ原题链接

洛谷原题链接

若第\(i\)个点不是割点,那么只有这个点单独形成一个连通块,其它点依旧连通,则答案为\(2\times (n-1)\)。

若第\(i\)个点是割点,那么去掉这个点相关的边就会形成\(3\)种构成的连通块:

  1. 由点\(i\)本身构成。
  2. 由点\(i\)的子树(搜索树中)形成若干个连通块。
  3. 由除点\(i\)及其子树的所有其它点构成一个连通块。

于是我们可以在用\(tarjan\)找割点的过程中计算搜索树中每棵子树的大小,并统计答案即可。

#include<cstdio>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
const int M = 5e5 + 10;
int fi[N], di[M << 1], ne[M << 1], dfn[N], low[N], si[N], l, ti, n;
bool v[N];
ll S[N];
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + (c - '0');
return p ? -x : x;
}
inline void add(int x, int y)
{
di[++l] = y;
ne[l] = fi[x];
fi[x] = l;
}
inline int minn(int x, int y)
{
return x < y ? x : y;
}
void tarjan(int x)
{
int i, y, s = 0, g = 0;
dfn[x] = low[x] = ++ti;
si[x] = 1;
for (i = fi[x]; i; i = ne[i])
{
y = di[i];
if (!dfn[y])
{
tarjan(y);
si[x] += si[y];
low[x] = minn(low[x], low[y]);
if (low[y] >= dfn[x])
{
g++;
S[x] += 1LL * si[y] * (n - si[y]);
s += si[y];
if (x ^ 1 || g > 1)
v[x] = 1;
}
}
else
low[x] = minn(low[x], dfn[y]);
}
if (v[x])
S[x] += 1LL * (n - 1 - s) * (s + 1) + n - 1;
else
S[x] = (n - 1) << 1;
}
int main()
{
int i, x, y, m;
n = re();
m = re();
for (i = 1; i <= m; i++)
{
x = re();
y = re();
add(x, y);
add(y, x);
}
tarjan(1);
for (i = 1; i <= n; i++)
printf("%lld\n", S[i]);
return 0;
}

BZOJ1123或洛谷3469 [POI2008]BLO-Blockade的更多相关文章

  1. 「洛谷3469」「POI2008」BLO-Blockade【Tarjan求割点】

    题目链接 [洛谷传送门] 题解 很显然,当这个点不是割点的时候,答案是\(2*(n-1)\) 如果这个点是割点,那么答案就是两两被分开的联通分量之间求组合数. 代码 #include <bits ...

  2. 洛谷 P3478 [POI2008]STA-Station

    题目描述 The first stage of train system reform (that has been described in the problem Railways of the ...

  3. 洛谷 P3477 [POI2008]PER-Permutation 解题报告

    P3477 [POI2008]PER-Permutation 题目描述 Multiset is a mathematical object similar to a set, but each mem ...

  4. 洛谷P3478 [POI2008]STA-Station

    P3478 [POI2008]STA-Station 题目描述 The first stage of train system reform (that has been described in t ...

  5. 洛谷 P3467 [POI2008]PLA-Postering

    P3467 [POI2008]PLA-Postering 题目描述 All the buildings in the east district of Byteburg were built in a ...

  6. 洛谷 P3469 [POI2008]BLO-Blockade (Tarjan,割点)

    P3469 [POI2008]BLO-Blockade https://www.luogu.org/problem/P3469 题目描述 There are exactly nn towns in B ...

  7. 洛谷P3469[POI2008]BLO-Blockade

    题目 割点模板题. 可以将图中的所有点分成两部分,一部分是去掉之后不影响图的连通性的点,一部分是去掉之后影响连通性的点,称其为割点. 然后分两种情况讨论,如果该点不是割点,则最终结果直接加上2*(n- ...

  8. 割点判断+luogu 3469 POI2008 BLO

    1.根节点,有2棵及以上子树 2.非根节点,有子节点dfn[u]<=low[v] #include <bits/stdc++.h> #define N 1000050 using n ...

  9. 【洛谷P3469】BLO

    题目大意:给定 N 个点,M 条边的联通无向图,求出对于每个点来说,将与这个点相连的所有边都去掉后,会少多少个联通的点对 (x,y). 题解:连通性问题从 DFS 树的角度进行考虑.对于 DFS 树当 ...

随机推荐

  1. js基础-类型转换

    显示类型转换 Number() 将任意类型转换数值类型 true 1 false 0 Number(null) => 0 Number(undefined) => NAN Number(' ...

  2. centos 7.4安装教程

    1. 2. 3. 4. 5. 6. 7. 8.

  3. Spring 手动 提交事务

    1.配置文件 applicationContext.xml: <bean id="txManager"class="org.springframework.jdbc ...

  4. linux安装jdk以及tomcat

    一.卸载旧jdk 1.检测原OPENJDK版本 java -version 查看是否安装了jdk,并且是什么版本 2.进一步查看JDK信息 rpm -qa|grep java tzdata-java- ...

  5. springboot 缓存

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...

  6. JS的6种常见继承模式

    数天前在知乎看到有人阿里面试被问到这个问题,我来总结一下. 1. 原型链继承: function SuperType() { this.property = true; } SuperType.pro ...

  7. js获取当前网页header头部信息

    思路,通过ajax重新请求当前页面,用getAllResponseHeaders方法获取: var req = new XMLHttpRequest();req.open('GET', documen ...

  8. poj3292(筛法+打表)

    题目链接:https://vjudge.net/problem/POJ-3292 题意:定义4n+1数(简称H数),H数分为三类:unit,即为1; H-primes,只能分解为1×自身,类似于我们平 ...

  9. python if __name__ == 'main' 的作用和原理()

    相信初学者在学习Python的过程中,不可避免的总会遇到 if __name__ == 'main'语句,虽然一直知道它的作用,但是可能一直比较模糊,今天菜鸟分析就与大家一起举例说说我的理解. 举个例 ...

  10. 【python】入门指南1

    基础的数据结构:int, float, string 注意:python入门系列的文章的示例均使用python3来完成. #!/bin/python a = 1 b = 1.0 c = 'string ...