当前位置:网站首页>【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;
}
边栏推荐
- WebView的优化与常见问题解决方案
- Fragment-hide and show
- C#报错 The ‘xmins‘ attribute is not supported in this context
- Codeforces Round #276 (Div. 1) B. Maximum Value
- Import other custom namespaces in C#
- Codeforces Round #276 (Div. 1) B. Maximum Value
- Cloud Migration Practice of Redis
- 2022-08-09:以下go语言代码输出什么?A:否,会 panic;B:是,能正确运行;C:不清楚,看投票结果。 package main import ( “fmt“ “syn
- 矩阵键盘&基于51(UcosII)计算器小项目
- 22!Beijing Changping District notified catering service enterprises with food safety problems
猜你喜欢
专有云ABC Stack,真正的实力派!
BEVDet4D: Exploit Temporal Cues in Multi-camera 3D Object Detection 论文笔记
【ECCV 2022|百万奖金】PSG大赛:追求“最全面”的场景理解
瑞幸「翻身」?恐言之尚早
【学习笔记】Redis的持久化
Redis上云迁移实践
Redis 定长队列的探索和实践
网络安全——XSS之被我们忽视的Cookie
Nanodlp v2.2/v3.0 light curing circuit board, connection method of mechanical switch/photoelectric switch/proximity switch and system state level setting
Stream通过findFirst()查找满足条件的一条数据
随机推荐
Network Saboteur
C#WPF 图片在显示时没有问题,但在运行时图片显示不出来的解决
YTU 2295: KMP pattern match one (string)
交换机的基础知识
神经网络可视化有3D版本了,美到沦陷!(已开源)
Borg Maze (bfs+最小生成树)
the height of the landscape
Matlab画分段函数「建议收藏」
Keithley DMM7510 accurate measurement of ultra-low power consumption equipment all kinds of operation mode power consumption
Makefile missing separator. Stop.怎么解决「建议收藏」
NodeJs原理 - Stream(二)
领域驱动实践总结(基本理论总结与分析V+架构分析与代码设计+具体应用设计分析)
Fragment-hide and show
3DS MAX batch export file script MAXScript with interface
AtCoder初学者比赛077 D -小多
Proprietary cloud ABC Stack, the real strength!
需要被记录的OpenStack相关的命令_自己用
Merge similar items in LeetCode simple questions
代码随想录笔记_动态规划_70爬楼梯
3DS MAX 批量导出文件脚本 MAXScript 带界面