割点判断+luogu 3469 POI2008 BLO
1.根节点,有2棵及以上子树
2.非根节点,有子节点dfn[u]<=low[v]
- #include <bits/stdc++.h>
- #define N 1000050
- using namespace std;
- inline int read(){
- int x=,f=;char ch=getchar();
- while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
- while(isdigit(ch)){x=(x<<)+(x<<)+(ch^);ch=getchar();}
- return x*f;
- }
- int head[N],dfn[N],low[N],cut[N];
- int cnt,idx;
- struct node{int v,next;}e[*N];
- void insert(int u,int v){
- e[++cnt]=(node){v,head[u]};head[u]=cnt;
- e[++cnt]=(node){u,head[v]};head[v]=cnt;
- }
- void tarjan(int u,int f){
- dfn[u]=low[u]=++idx;
- int rs=;
- for(int i=head[u];i;i=e[i].next){
- int v=e[i].v;
- if(!dfn[v]){
- tarjan(v,f);rs++;
- low[u]=min(low[u],low[v]);
- if((u==f&&<=rs)||(u!=f&&dfn[u]<=low[v]))
- cut[u]=;
- }else
- low[u]=min(low[u],dfn[v]);
- }
- }
- int n,m,ans;
- int main(){
- n=read(),m=read();
- for(int i=;i<=m;i++){
- int x=read(),y=read();
- insert(x,y);
- }
- for(int i=;i<=n;i++)
- if(!dfn[i]) tarjan(i,i);
- for(int i=;i<=n;i++)
- if(cut[i]) ans++;
- printf("%d\n",ans);
- for(int i=;i<=n;i++)
- if(cut[i]) printf("%d ",i);
- return ;
- }
割点+树形dp
在同一连通块内用z累计大小(除u节点)
判断割点并累加内部答案,
最后累加连通块内部与外界答案
树形dp+割点tarjan
- #include<bits/stdc++.h>
- #define ll long long
- const int N=;
- const int M=;
- using namespace std;
- int dfn[N],low[N],siz[N],cut[N];
- ll ans[N];
- inline int read(){
- int x=,f=;char ch=getchar();
- while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
- while(isdigit(ch)){x=(x<<)+(x<<)+(ch^);ch=getchar();}
- return x*f;}
- int head[N],tot,idx,n,m,x,y;
- struct node{int v,next;}e[M];
- void insert(int u,int v){
- e[++tot]=(node){v,head[u]};head[u]=tot;
- e[++tot]=(node){u,head[v]};head[v]=tot;}
- int tarjan(int u){
- int z=;siz[u]=;
- dfn[u]=low[u]=++idx;
- for(int i=head[u];i;i=e[i].next){
- int v=e[i].v;
- if(!dfn[v]){
- tarjan(v);
- siz[u]+=siz[v];
- low[u]=min(low[u],low[v]);
- if(dfn[u]<=low[v]){
- ans[u]+=(ll)z*siz[v];
- z+=siz[v];}
- //连通块内部的累加答案
- }else low[u]=min(low[u],dfn[v]);
- }ans[u]+=(ll)z*(n-z-);//此连通块内部和外部(除本节点)的累加答案
- }
- int main(){
- n=read();m=read();
- for(int i=;i<=m;i++)
- x=read(),y=read(),insert(x,y);
- tarjan();
- for(int i=;i<=n;i++)
- printf("%lld\n",(ans[i]+n-)<<);return ;
- }
割点判断+luogu 3469 POI2008 BLO的更多相关文章
- bzoj 1123 [POI2008]BLO Tarjan求割点
[POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1540 Solved: 711[Submit][Status][Discu ...
- [Luogu P3469] [POI2008]BLO-Blockade (割点)
题面 传送门:https://www.luogu.org/problemnew/show/P3469 Solution 先跟我大声念: poi! 然后开始干正事. 首先,我们先把题目中的点分为两类:去 ...
- BZOJ 1123: [POI2008]BLO
1123: [POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1030 Solved: 440[Submit][Status] ...
- BZOJ1123: [POI2008]BLO
1123: [POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 614 Solved: 235[Submit][Status] ...
- BZOJ 1123: [POI2008]BLO( tarjan )
tarjan找割点..不是割点答案就是(N-1)*2, 是割点的话就在tarjan的时候顺便统计一下 ------------------------------------------------- ...
- [POI2008]BLO(Tarjan)
[POI2008]BLO Description Byteotia城市有\(n\)个 towns \(m\)条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所 ...
- BZOJ1123 [POI2008]BLO(割点判断 + 点双联通缩点size)
#include <iostream> #include <cstring> #include <cstdio> using namespace std; type ...
- 【bzoj1123】【[POI2008]BLO】tarjan判割点
(上不了p站我要死了,侵权度娘背锅) Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有t ...
- BZOJ 1123 && Luogu P3469 [POI2008]BLO-Blockade 割点+乘法原理
想了半天式子...最后在邓大师的帮助下想出此题....QWQ我还是太菜了 对于一个非割点,ans+=2*(n-1); 对于一个割点,ans+= #include<cstdio> #incl ...
随机推荐
- A.01.02—模块的输入—高端输入
高端输入即一个高电平信号输入到模块,模块采样时最典型的是采用下拉电阻采样,当然,还有限流电阻和分压电阻,具体可以参见实际电路. 高端输入在汽车上用得不多,这种类型的输入既可以是开关提供的也可以是模块提 ...
- docker 使用指南
Compose is a tool for defining and running multi-container Docker applications. With Compose, you us ...
- Git设置彩色输出
彩色输出 git config --global color.status auto git config --global color.diff auto git config --global c ...
- 如何写一个通用的README规范
背景 我们平常在进行项目开发时,一般都会把代码上传至代码托管平台上方便管理和维护.目前我厂使用的托管平台是SVN,国内外还有一些比较知名的代码托管平台,比如github.Gitlab.BitBucke ...
- [luogu4556][Vani有约会]
题目链接 吐槽 这道题调了7个小时也是够了.最后只好比着题解做了一遍2333 思路 首先考虑n=2000的情况.因为这是在一条路径上,所以可以考虑差分.用a[i][j]表示第i个点中j这种粮食出现的次 ...
- 最短路 次短路 k短路(k很小)
最短路 luogu 3371 https://www.luogu.org/problemnew/show/P3371 #include <cstdio> #include <cstd ...
- linux 系统调用之文件操作
fcntl 文件控制 open 打开文件 creat 创建新文件 close 关闭文件描述字 read 读文件 write 写文件 readv 从文件读入数据到缓冲数组中 writev 将缓冲数组里的 ...
- Gym - 101755G Underpalindromity (树状数组)
Let us call underpalindromity of array b of length k the minimal number of times one need to increme ...
- SQL Server 经典案例
1.先进先出 例1 WITH [ta] ([商品编号], [批次号], [库存数量]) AS ( UNION ALL UNION ALL UNION ALL ),[tb] ([商品编号], [订货数量 ...
- angular 中自己常用的下拉框获取值方法
方法一 HTML页中 <select name="" id="if02" data-first-option="true" (chan ...