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的心路历程 - PixiJS -基础(三)

    今天我们来试着移动图片吧! 首先,一样先把图片放到PIXI的stage中: let app = new PIXI.Application({ width: 800, height: 600, back ...

  2. Promise 学习

    参考 https://www.jianshu.com/p/43f948051d65 // Promise里面传入一个函数类型的参数,这个函数类型的参数接收两个参数resolve reject var ...

  3. ASP.NET 分页+组合查询 练习

    分页和组合查询都是通过拼接SQL语句到数据库查询进行实现 到汽车表(car)中查询 ,汽车表选取了“编号 code”,“车名 name”,“日期 time”,“油耗 oil ”,“马力 powers” ...

  4. 动态代理 JDK动态代理 CGLIB代理

    代理模式:代理类和被代理类实现共同的接口(或继承),代理类中存有指向被代理类的索引,实际执行时通过调用代理类的方法.实际执行的是被代理类的方法. 而AOP,是通过动态代理实现的. 一.简单来说: JD ...

  5. JDBC的基本概念

    英文名:Java DataBase Connectivity 中文名:数据库连接 作用: java操作数据库 本质上(sun公司的程序员)定义的一套操作关系型数据库的规则也就是接口,各数据库厂商实现接 ...

  6. Numeric Type Attributes

    [Numeric Type Attributes]  INT(4) specifies an INT with a display width of four digits. This optiona ...

  7. pip安装离线包

    离线包从pypi.org下载 pip download  -r requirements.txt  -d  /tmp/paks/ 在linux下       1.下载指定的包到指定文件夹.       ...

  8. 解题8(FindLongestNumberStr)

    题目描述 样例输出 输出123058789,函数返回值9 输出54761,函数返回值5 接口说明 函数原型: unsignedint Continumax(char** pOutputstr,  ch ...

  9. sqlserver 无法打开备份文件a.bak

    bak文件不能放在磁盘根目录,放到文件夹下即可.

  10. 22. Generate Parentheses (backTracking)

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...