1.根节点,有2棵及以上子树

2.非根节点,有子节点dfn[u]<=low[v]

  1. #include <bits/stdc++.h>
  2. #define N 1000050
  3. using namespace std;
  4.  
  5. inline int read(){
  6. int x=,f=;char ch=getchar();
  7. while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
  8. while(isdigit(ch)){x=(x<<)+(x<<)+(ch^);ch=getchar();}
  9. return x*f;
  10. }
  11.  
  12. int head[N],dfn[N],low[N],cut[N];
  13. int cnt,idx;
  14. struct node{int v,next;}e[*N];
  15. void insert(int u,int v){
  16. e[++cnt]=(node){v,head[u]};head[u]=cnt;
  17. e[++cnt]=(node){u,head[v]};head[v]=cnt;
  18. }
  19. void tarjan(int u,int f){
  20. dfn[u]=low[u]=++idx;
  21. int rs=;
  22. for(int i=head[u];i;i=e[i].next){
  23. int v=e[i].v;
  24. if(!dfn[v]){
  25. tarjan(v,f);rs++;
  26. low[u]=min(low[u],low[v]);
  27. if((u==f&&<=rs)||(u!=f&&dfn[u]<=low[v]))
  28. cut[u]=;
  29. }else
  30. low[u]=min(low[u],dfn[v]);
  31. }
  32. }
  33. int n,m,ans;
  34.  
  35. int main(){
  36. n=read(),m=read();
  37. for(int i=;i<=m;i++){
  38. int x=read(),y=read();
  39. insert(x,y);
  40. }
  41. for(int i=;i<=n;i++)
  42. if(!dfn[i]) tarjan(i,i);
  43. for(int i=;i<=n;i++)
  44. if(cut[i]) ans++;
  45. printf("%d\n",ans);
  46. for(int i=;i<=n;i++)
  47. if(cut[i]) printf("%d ",i);
  48. return ;
  49. }

割点+树形dp

在同一连通块内用z累计大小(除u节点)

判断割点并累加内部答案,

最后累加连通块内部与外界答案

树形dp+割点tarjan

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. const int N=;
  4. const int M=;
  5. using namespace std;
  6.  
  7. int dfn[N],low[N],siz[N],cut[N];
  8. ll ans[N];
  9. inline int read(){
  10. int x=,f=;char ch=getchar();
  11. while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
  12. while(isdigit(ch)){x=(x<<)+(x<<)+(ch^);ch=getchar();}
  13. return x*f;}
  14. int head[N],tot,idx,n,m,x,y;
  15. struct node{int v,next;}e[M];
  16. void insert(int u,int v){
  17. e[++tot]=(node){v,head[u]};head[u]=tot;
  18. e[++tot]=(node){u,head[v]};head[v]=tot;}
  19. int tarjan(int u){
  20. int z=;siz[u]=;
  21. dfn[u]=low[u]=++idx;
  22. for(int i=head[u];i;i=e[i].next){
  23. int v=e[i].v;
  24. if(!dfn[v]){
  25. tarjan(v);
  26. siz[u]+=siz[v];
  27. low[u]=min(low[u],low[v]);
  28. if(dfn[u]<=low[v]){
  29. ans[u]+=(ll)z*siz[v];
  30. z+=siz[v];}
  31. //连通块内部的累加答案
  32. }else low[u]=min(low[u],dfn[v]);
  33. }ans[u]+=(ll)z*(n-z-);//此连通块内部和外部(除本节点)的累加答案
  34. }
  35. int main(){
  36. n=read();m=read();
  37. for(int i=;i<=m;i++)
  38. x=read(),y=read(),insert(x,y);
  39. tarjan();
  40. for(int i=;i<=n;i++)
  41. printf("%lld\n",(ans[i]+n-)<<);return ;
  42. }

割点判断+luogu 3469 POI2008 BLO的更多相关文章

  1. bzoj 1123 [POI2008]BLO Tarjan求割点

    [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1540  Solved: 711[Submit][Status][Discu ...

  2. [Luogu P3469] [POI2008]BLO-Blockade (割点)

    题面 传送门:https://www.luogu.org/problemnew/show/P3469 Solution 先跟我大声念: poi! 然后开始干正事. 首先,我们先把题目中的点分为两类:去 ...

  3. BZOJ 1123: [POI2008]BLO

    1123: [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1030  Solved: 440[Submit][Status] ...

  4. BZOJ1123: [POI2008]BLO

    1123: [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 614  Solved: 235[Submit][Status] ...

  5. BZOJ 1123: [POI2008]BLO( tarjan )

    tarjan找割点..不是割点答案就是(N-1)*2, 是割点的话就在tarjan的时候顺便统计一下 ------------------------------------------------- ...

  6. [POI2008]BLO(Tarjan)

    [POI2008]BLO Description Byteotia城市有\(n\)个 towns \(m\)条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所 ...

  7. BZOJ1123 [POI2008]BLO(割点判断 + 点双联通缩点size)

    #include <iostream> #include <cstring> #include <cstdio> using namespace std; type ...

  8. 【bzoj1123】【[POI2008]BLO】tarjan判割点

    (上不了p站我要死了,侵权度娘背锅) Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有t ...

  9. BZOJ 1123 && Luogu P3469 [POI2008]BLO-Blockade 割点+乘法原理

    想了半天式子...最后在邓大师的帮助下想出此题....QWQ我还是太菜了 对于一个非割点,ans+=2*(n-1); 对于一个割点,ans+= #include<cstdio> #incl ...

随机推荐

  1. A.01.02—模块的输入—高端输入

    高端输入即一个高电平信号输入到模块,模块采样时最典型的是采用下拉电阻采样,当然,还有限流电阻和分压电阻,具体可以参见实际电路. 高端输入在汽车上用得不多,这种类型的输入既可以是开关提供的也可以是模块提 ...

  2. docker 使用指南

    Compose is a tool for defining and running multi-container Docker applications. With Compose, you us ...

  3. Git设置彩色输出

    彩色输出 git config --global color.status auto git config --global color.diff auto git config --global c ...

  4. 如何写一个通用的README规范

    背景 我们平常在进行项目开发时,一般都会把代码上传至代码托管平台上方便管理和维护.目前我厂使用的托管平台是SVN,国内外还有一些比较知名的代码托管平台,比如github.Gitlab.BitBucke ...

  5. [luogu4556][Vani有约会]

    题目链接 吐槽 这道题调了7个小时也是够了.最后只好比着题解做了一遍2333 思路 首先考虑n=2000的情况.因为这是在一条路径上,所以可以考虑差分.用a[i][j]表示第i个点中j这种粮食出现的次 ...

  6. 最短路 次短路 k短路(k很小)

    最短路 luogu 3371 https://www.luogu.org/problemnew/show/P3371 #include <cstdio> #include <cstd ...

  7. linux 系统调用之文件操作

    fcntl 文件控制 open 打开文件 creat 创建新文件 close 关闭文件描述字 read 读文件 write 写文件 readv 从文件读入数据到缓冲数组中 writev 将缓冲数组里的 ...

  8. Gym - 101755G Underpalindromity (树状数组)

    Let us call underpalindromity of array b of length k the minimal number of times one need to increme ...

  9. SQL Server 经典案例

    1.先进先出 例1 WITH [ta] ([商品编号], [批次号], [库存数量]) AS ( UNION ALL UNION ALL UNION ALL ),[tb] ([商品编号], [订货数量 ...

  10. angular 中自己常用的下拉框获取值方法

    方法一 HTML页中 <select name="" id="if02" data-first-option="true" (chan ...