当前位置:网站首页>【POI 2008, BLO】Cut Point
【POI 2008, BLO】Cut Point
2022-08-10 13:33:00 【Uchiha one hit seven~】
题目描述
有n个点mA graph of edge undirected connected graphs,保证没有重边和自环.对于每个点,The output removes all edges from this point,How many point pairs cannot be connected to each other.The point pairs here are in order,也就是(u,v)和(v,u)need to be counted twice.
输入格式
第一行包含两个数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
思路
对于每一个点,如果这个点是割点,Then after deleting him, it has no effect on this picture,So the contribution of this point is2*(n-1),If this point is a cut point,Then multiply all the connected blocks that delete it,Pay attention to the process of seeking that cut edge,That is, if the point connected to this point does not have a leaseback edge, it is a cut point,下面看代码吧
#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;
}
边栏推荐
- Basic knowledge of switches
- 八大排序总是忘?快来这里~
- 【黑马早报】雷军称低谷期曾想转行开酒吧;拜登正式签署芯片法案;软银二季度巨亏230亿美元;北京市消协约谈每日优鲜...
- 教育Codeforces轮41(额定Div。2)大肠Tufurama
- Keithley DMM7510 accurate measurement of ultra-low power consumption equipment all kinds of operation mode power consumption
- jenkins数据迁移和备份
- 山水的高度
- Makefile missing separator. Stop.怎么解决「建议收藏」
- 作业8.9 构建TCP协议的服务器
- Wirshark common operations and tcp three-way handshake process example analysis
猜你喜欢
随机推荐
SenseTime self-developed robotic arm, the first product is an AI chess-playing robot: Guo Jingjing is also invited as an endorsement
【量化交易行情不够快?】一文搞定通过Win10 wsl2 +Ubuntu+redis+pickle实现股票行情极速读写
八大排序总是忘?快来这里~
接口自动化测试基础篇
生成树协议STP(Spanning Tree Protocol)
Overview of Loudi Petrochemical Experiment Design and Construction Planning
神了!阿里数据库专家纯手写了这份604页的Oracle+MySQL攻坚指南
领域驱动实践总结(基本理论总结与分析V+架构分析与代码设计+具体应用设计分析)
Efficient and Robust 2D-to-BEV Representation Learning via Geometry-guided Kernel Transformer Paper Notes
C# WPF image is displayed without problems, but the solution does not display the image at runtime
Redis 定长队列的探索和实践
Ethernet channel 以太信道
CodeForces - 811A
【JS高级】ES5标准规范之创建子对象以及替换this_10
跨域的五种解决方案
Nanodlp v2.2/v3.0 light curing circuit board, connection method of mechanical switch/photoelectric switch/proximity switch and system state level setting
Ethernet channel Ethernet channel
商汤自研机械臂,首款产品是AI下棋机器人:还请郭晶晶作代言
把相亲角搬到海外,不愧是咱爸妈
2022-08-09:以下go语言代码输出什么?A:否,会 panic;B:是,能正确运行;C:不清楚,看投票结果。 package main import ( “fmt“ “syn