当前位置:网站首页>【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的优化与常见问题解决方案
- 22!Beijing Changping District notified catering service enterprises with food safety problems
- [Advanced Digital IC Verification] Difference and focus analysis between SoC system verification and IP module verification
- bgp双平面实验 路由策略控制流量
- 系统的安全和应用(不会点安全的东西你怎么睡得着?)
- 燃炸!字节跳动成功上岸,只因刷爆LeetCode算法面试题
- MYSQL误删数据恢复
- CodeForces - 834C
- Short read or OOM loading DB. Unrecoverable error, aborting now
- Fragment's show and hide
猜你喜欢
LeetCode·297.二叉树的序列化与反序列化·DFS·BFS
来看Prada大秀吗?在元宇宙里那种!
在web页面播放rtsp流视频(webrtc)
Interface Automation Testing Basics
Basic knowledge of switches
交换机的基础知识
作业8.9 构建TCP协议的服务器
2022年五大云虚拟化趋势
[target detection] small script: extract training set images and labels and update the index
ArcMAP has a problem of -15 and cannot be accessed [Provide your license server administrator with the following information:Err-15]
随机推荐
C# error The 'xmins' attribute is not supported in this context
Detailed explanation of es6-promise object
Redis上云迁移实践
进程和计划任务管理
Matrix Keyboard & Calculator Small Project Based on 51 (UcosII)
2022-08-09:以下go语言代码输出什么?A:否,会 panic;B:是,能正确运行;C:不清楚,看投票结果。 package main import ( “fmt“ “syn
kubernetes介绍
A can make large data clustering method of 2000 times faster, don't poke
数字藏品,“赌”字当头
LeetCode·每日一题·640.求解方程·模拟构造
跨域的五种解决方案
A detailed explanation of implementation api embed
Redis 定长队列的探索和实践
商汤自研机械臂,首款产品是AI下棋机器人:还请郭晶晶作代言
日志@Slf4j介绍使用及配置等级
Jenkins修改端口号, jenkins容器修改默认端口号
[Study Notes] Persistence of Redis
浙大、阿里提出DictBERT,字典描述知识增强的预训练语言模型
Network Saboteur
【iOS】Organization of interviews