题目链接:https://www.luogu.org/problemnew/show/P3469

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 500000 + 10;
ll n, m, ans[maxn];
ll dfn[maxn], low[maxn], tim, size[maxn];
bool iscut[maxn];
struct edge{
ll from, to, next;
}e[maxn<<2];
ll head[maxn], cnt;
void add(ll u, ll v)
{
e[++cnt].from = u;
e[cnt].next = head[u];
e[cnt].to = v;
head[u] = cnt;
}
void tarjan(ll x, ll fa)
{
ll child = 0, sum = 0;
dfn[x] = low[x] = ++tim;
size[x] = 1;
for(ll i = head[x]; i != -1; i = e[i].next)
{
ll v = e[i].to;
if(!dfn[v])
{
tarjan(v,fa);
size[x] += size[v];
low[x] = min(low[x], low[v]);
if(low[v] >= dfn[x])
{
ans[x] += size[v]*(n - size[v]);
sum += size[v];
child++;
if(x != fa)
iscut[x] = 1;
}
if(x == fa) child++;
}
low[x] = min(low[x], dfn[v]);
}
if(x == fa && child >= 2) iscut[fa] = 1;
if(!iscut[x]) ans[x] = 2*(n-1);
else ans[x] += (n-sum-1)*(sum+1)+n-1;
}
int main()
{
memset(head, -1, sizeof(head));
scanf("%lld%lld",&n,&m);
for(ll i = 1; i <= m; i++)
{
ll u, v;
scanf("%lld%lld",&u,&v);
add(u,v),add(v,u);
}
tarjan(1,1);
for(ll i = 1; i <= n; i++)
printf("%lld\n",ans[i]);
return 0;
}

【luogu P3469 [POI2008]BLO-Blockade】 题解的更多相关文章

  1. [Luogu P3469] [POI2008]BLO-Blockade (割点)

    题面 传送门:https://www.luogu.org/problemnew/show/P3469 Solution 先跟我大声念: poi! 然后开始干正事. 首先,我们先把题目中的点分为两类:去 ...

  2. [LUOGU] P3469 [POI2008]BLO-Blockade

    https://www.luogu.org/problemnew/show/P3469 求无向图分别删去每个点后不连通的点对数. 首先,对于任何一个点,它本身删了,就会和剩下的n-1个点不连通,点对是 ...

  3. 割点判断+luogu 3469 POI2008 BLO

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

  4. BZOJ 1123 && Luogu P3469 [POI2008]BLO-Blockade 割点+乘法原理

    想了半天式子...最后在邓大师的帮助下想出此题....QWQ我还是太菜了 对于一个非割点,ans+=2*(n-1); 对于一个割点,ans+= #include<cstdio> #incl ...

  5. BZOJ1123: [POI2008]BLO

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

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

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

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

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

  8. BZOJ 1123: [POI2008]BLO

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

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

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

随机推荐

  1. The Java serialization algorithm revealed---reference

    Serialization is the process of saving an object's state to a sequence of bytes; deserialization is ...

  2. SpringBoot | 第二十九章:Dubbo的集成和使用

    前言 今年年初时,阿里巴巴开源的高性能服务框架dubbo又开始了新一轮的更新,还加入了Apache孵化器.原先项目使用了spring cloud之后,已经比较少用dubbo.目前又抽调回原来的行业应用 ...

  3. 深入理解JavaScript系列(37):设计模式之享元模式

    介绍 享元模式(Flyweight),运行共享技术有效地支持大量细粒度的对象,避免大量拥有相同内容的小类的开销(如耗费内存),使大家共享一个类(元类). 享元模式可以避免大量非常相似类的开销,在程序设 ...

  4. 数组和矩阵(2)——Reshape the Matrix

    In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...

  5. HttpComponents

    一 概述 1.HttpComponents的作用 HttpComponents的作用是模拟浏览器获取网页内容. 二 使用 1.使用HttpComponents需要先导入架包. 2.使用 Closeab ...

  6. html5 填表 表单 input output 与表单验证

    1.<output>     Js计算结果 <form oninput="res.value = num1.valueAsNumber*num2.valueAsNumber ...

  7. 如何才能快速入门python3?

    一些朋友自学python过程中,发现书也能看懂,书上的玩具代码也能看懂,但为啥自己不能做习题,不能写代码解决问题,自己不能动手写代码? 原因是初学者没有学会计算思维.解决问题的方法.编程思路. 编程思 ...

  8. 详细分析UserLock如何保证高校内部信息安全

    俄克拉荷马城市公立学校的IT团队负责该片区接近43000个学生的网络管理工作.长期以来,学生和教师员工共享Windows网络登录为他们带来了很多难题. 由于没有并发登录的限制,也不能对网络使用情况进行 ...

  9. matlab练习程序(随机游走图像)

    随机游走类似布朗运动,就是随机的向各个方向走吧. 虽然代码没什么技术含量,不过产生的图像实在太漂亮了,所以还是贴上来吧. 产生的图像: matlab代码如下: clear all;close all; ...

  10. 向jsp页面传值时出现乱码

    在一个html页面中用表单向jsp页面传值: 这是html页面 <html> <head> <title>MyBeans.html</title> &l ...