当前位置:网站首页>【POI 2008, BLO】割点
【POI 2008, BLO】割点
2022-08-10 13:00:00 【宇智波一打七~】
题目描述
有n个点m条边无向连通图的图,保证没有重边和自环。对于每个点,输出将这个点的所有边删除之后,有多少点对不能互相连通。这里的点对是有顺序的,也就是(u,v)和(v,u)需要被统计两次。
输入格式
第一行包含两个数n,m(1≤n≤105,1≤m≤5×105)。
接下来m行,每行两个整数u,v表示一条无向边。
输出格式
n行,每行一个整数,表示答案。
样例输入
5 5
1 2
2 3
1 3
3 4
4 5
样例输出
8
8
16
14
8
思路
对于每一个点,如果这个点是割点,那么删了他之后对这个图来说是没有影响的,所以说这个点的贡献就是2*(n-1),如果这个点是割点的话,那么对于把它删去的所有连通块都乘一下就行,注意求那个割边的过程,就是如果与这个点相连的点没有返租边的话那就是割点了,下面看代码吧
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 1e5+10;
vector<pair<int,int> > e[N];
int n,m,dfn[N],ins[N],low[N],idx,sz[N];
long long ans[N];
void dfs(int u,int id){
dfn[u] = low[u] = ++idx;
ins[u] = true;
sz[u] = 1;
ans[u] = n-1;
int cut = n-1;
for(auto pi : e[u]){
int v = pi.first,idd = pi.second;
if(!dfn[v]){
dfs(v,idd);
sz[u] += sz[v];
low[u] = min(low[u],low[v]);
if(low[v] >= dfn[u]){
ans[u] += 1ll*(n-sz[v])*sz[v];
cut -= sz[v];
}
}
else if(idd != id){
low[u] = min(low[u],dfn[v]);
}
}
ans[u] += 1ll*(cut)*(n-cut);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int a,b;
scanf("%d%d",&a,&b);
e[a].pb({
b,i});e[b].pb({
a,i});
}
dfs(1,-1);
for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
return 0;
}
边栏推荐
- [Advanced Digital IC Verification] Difference and focus analysis between SoC system verification and IP module verification
- 高数_证明_弧微分公式
- C# InitializeComponent() does not exist in the current context
- 表中存在多个索引问题? - 聚集索引,回表,覆盖索引
- BEVDet4D: Exploit Temporal Cues in Multi-camera 3D Object Detection Paper Notes
- 11+ chrome高级调试技巧,学会效率直接提升666%
- 【学习笔记】Redis的持久化
- recursive recursive function
- C# error The 'xmins' attribute is not supported in this context
- Cloud Migration Practice of Redis
猜你喜欢

ABAP file operations involved in the Chinese character set of problems and solutions for trying to read

kubernetes介绍

Short read or OOM loading DB. Unrecoverable error, aborting now

Stream通过findFirst()查找满足条件的一条数据

【量化交易行情不够快?】一文搞定通过Win10 wsl2 +Ubuntu+redis+pickle实现股票行情极速读写

LeetCode medium topic search of two-dimensional matrix

2022 Recruitment Notice for Academician Zhao Guoping Group of Shenzhen Institute of Advanced Technology, Chinese Academy of Sciences

Efficient and Robust 2D-to-BEV Representation Learning via Geometry-guided Kernel Transformer 论文笔记

2022-08-09: What does the following go code output?A: No, it will panic; B: Yes, it can run correctly; C: Not sure, see the voting result.package main import (“fmt“ “syn

专有云ABC Stack,真正的实力派!
随机推荐
Network Saboteur
Loudi Center for Disease Control and Prevention Laboratory Design Concept Description
友邦人寿可观测体系设计与落地
Loudi Cosmetics Laboratory Construction Planning Concept
Codeforces Round #276 (Div. 1) B. Maximum Value
YTU 2295: KMP pattern match one (string)
OpenStack-related commands that need to be recorded _ self-use
金山云要飘到哪里?
The recursive recursive Fighting_ silver study ah but level 4
ArcMAP has a problem of -15 and cannot be accessed [Provide your license server administrator with the following information:Err-15]
LeetCode·297.二叉树的序列化与反序列化·DFS·BFS
C# 当前上下文中不存在InitializeComponent()
学习日记9
YTU 2295: KMP模式匹配 一(串)
Jenkins修改默认主目录
es6-promise对象详解
jenkins数据迁移和备份
作业8.9 构建TCP协议的服务器
C#报错 The ‘xmins‘ attribute is not supported in this context
矩阵键盘&基于51(UcosII)计算器小项目