洛谷 [P3496] BLO
割点
首先 tarjan 求割点,
对于不是割点的点, 答案是 2 * (n-1) 有序,所以要乘 2
对于是割点的点, 答案是删去该点后所有连通块的个数加上 n-1 在乘 2
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int MAXN = 1000005;
ll ans[MAXN];
int head[MAXN], n, m, nume, dfn[MAXN], low[MAXN], ind, siz[MAXN];
bool f[MAXN];
struct edge{
int to, nxt;
}e[MAXN];
void adde(int from, int to) {
e[++nume].to = to;
e[nume].nxt = head[from];
head[from] = nume;
}
int init() {
int rv = 0, fh = 1;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') fh = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
rv = (rv<<1) + (rv<<3) + c - '0';
c = getchar();
}
return fh * rv;
}
void tarjan(int u) {
dfn[u] = low[u] = ++ind;siz[u] = 1;
int flag = 0, sum = 0;
for(int i = head[u]; i; i = e[i].nxt) {
int v = e[i].to;
if(!dfn[v]) {
tarjan(v);
siz[u] += siz[v];
low[u] = min(low[u], low[v]);
if(low[v] >= dfn[u]) {
flag++;
ans[u] += (ll) siz[v] * (n - siz[v]);
sum += siz[v];
if(u != 1 || flag > 1) {
f[u] = 1;
}
}
}else low[u] = min(low[u], dfn[v]);
}
if(f[u]) ans[u] += (ll) (n - sum - 1) * (sum + 1) + n - 1;
else ans[u] = 2 * n - 2;
}
int main() {
n = init(); m = init();
for(int i = 1; i <= m; i++) {
int u = init(), v = init();
if(u == v) continue;
adde(u, v); adde(v, u);
}
tarjan(1);
for(int i = 1; i <= n; i++) printf("%lld\n", ans[i]);
return 0;
}
洛谷 [P3496] BLO的更多相关文章
- 洛谷 P3496 [POI2010]GIL-Guilds
P3496 [POI2010]GIL-Guilds 题目描述 King Byteasar faces a serious matter. Two competing trade organisatio ...
- 洛谷 P3496 BZOJ 2079 [POI2010]GIL-Guilds
题目描述 King Byteasar faces a serious matter. Two competing trade organisations, The Tailors Guild and ...
- 洛谷 P2802 回家
题目链接 https://www.luogu.org/problemnew/show/P2802 题目描述 小H在一个划分成了n*m个方格的长方形封锁线上. 每次他能向上下左右四个方向移动一格(当然小 ...
- 洛谷P3247 [HNOI2016]最小公倍数 [分块,并查集]
洛谷 思路 显然,为了达到这个最小公倍数,只能走\(a,b\)不是很大的边. 即,当前询问的是\(A,B\),那么我们只能走\(a\leq A,b\leq B\)的边. 然而,为了达到这最小公倍数,又 ...
- 洛谷P4117 [Ynoi2018]五彩斑斓的世界 [分块,并查集]
洛谷 Codeforces 又是一道卡常题-- 思路 YNOI当然要分块啦. 分块之后怎么办? 零散块暴力,整块怎么办? 显然不能暴力改/查询所有的.考虑把相同值的用并查集连在一起,这样修改时就只需要 ...
- Bzoj2038/洛谷P1494 小Z的袜子(莫队)
题面 Bzoj 洛谷 题解 考虑莫队算法,首先对询问进行分块(分块大小为\(sqrt(n)\)),对于同一个块内的询问,按照左端点为第一关键字,右端点为第二关键字排序.我们统计这个区间内相同的颜色有多 ...
- 洛谷P4198 楼房重建 (分块)
洛谷P4198 楼房重建 题目描述 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题, ...
- 洛谷P4135 作诗 (分块)
洛谷P4135 作诗 题目描述 神犇SJY虐完HEOI之后给傻×LYD出了一题: SHY是T国的公主,平时的一大爱好是作诗. 由于时间紧迫,SHY作完诗之后还要虐OI,于是SHY找来一篇长度为N的文章 ...
- 洛谷P3396 哈希冲突 (分块)
洛谷P3396 哈希冲突 题目背景 此题约为NOIP提高组Day2T2难度. 题目描述 众所周知,模数的hash会产生冲突.例如,如果模的数p=7,那么4和11便冲突了. B君对hash冲突很感兴趣. ...
随机推荐
- pycahrm git配置笔记
1. 在file - setting - plugins 中查看是否有github插件, 此处是用于处理插件位置
- ZendFramework-2.4 源代码 - 关于MVC - View层 - 视图渲染器、视图插件管理器
<?php // 1. 视图渲染器 class PhpRenderer implements Renderer, TreeRendererInterface { /** * 插件管理器 */ p ...
- thinkphp 3.2.3 - Route.class.php 解析(路由匹配)
class Route { public static function check(){ $depr = C('URL_PATHINFO_DEPR'); // '/' $regx = preg_re ...
- 免费证书Let’s Encrypt
我们自己也可以签发 SSL 安全证书,但是我们自己签发的安全证书不会被主流的浏览器信任,所以我们需要被信任的证书授权中心( CA )签发的安全证书.而一般的 SSL 安全证书签发服务都比较贵,比如 G ...
- proguaid 混淆代码
注意:这里有一个坑.就是-ignorewarnings 他老是混淆不了,告诉你不行.其实加上这句话,就可以了. 下面贴一下代码: -injars c:/ceb_lib.jar -outjars c:/ ...
- Nodejs-非阻塞I/O&事件驱动
1.关于es6变量 const 定义常量,不会发生改变的就用这个 let 定义局部变量 如: const fs=require('fs');//require()表示载入这个模块 function a ...
- This application has request the Runtime to terminate it in an unusual way.
Q: CertsMV.exe gui popup two dialogs as follow. A: 测试发现是分配内存导致,频繁分配内存(大约6M) 可能是堆管理导致 分配大内存分配失败,程序未对 ...
- 设计模式之序章-UML类图那点事儿
设计模式之序-UML类图那点事儿 序 打14年年底就像写那么一个系列,用于讲设计模式的,代码基于JAVA语言,最早接触设计模式是大一还是大二来着,那时候网上有人给推荐书,其中就有设计模式,当时给我推荐 ...
- 【Best Time to Buy and Sell Stock II】cpp
题目: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...
- 【Plus One】cpp
题目: Given a non-negative number represented as an array of digits, plus one to the number. The digit ...