BZOJ 1123 && Luogu P3469 [POI2008]BLO-Blockade 割点+乘法原理
想了半天式子。。。最后在邓大师的帮助下想出此题。。。。QWQ我还是太菜了
对于一个非割点,ans+=2*(n-1);
对于一个割点,ans+=
#include<cstdio> #include<iostream> #define R register int using namespace std; const int N=100010,M=500010; inline int g() { R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix; } int n,m,cnt=1,num; int vr[M<<1],nxt[M<<1],fir[N],dfn[N],low[N],sz[N]; long long ans[N]; bool cut[N]; inline void add(int u,int v) {vr[++cnt]=v,nxt[cnt]=fir[u],fir[u]=cnt;} void tarjan(int u) { dfn[u]=low[u]=++num,sz[u]=1; R sum=0,flg=0; for(R i=fir[u];i;i=nxt[i]) { R v=vr[i]; if(!dfn[v]) { tarjan(v); sz[u]+=sz[v]; low[u]=min(low[u],low[v]); if(low[v]>=dfn[u]) { ++flg; ans[u]+=1ll*sz[v]*(n-sz[v]); sum+=sz[v]; if(u!=1||flg>1) cut[u]=true; } } else low[u]=min(low[u],dfn[v]); } if(cut[u]) ans[u]+=1ll*(n-sum-1)*(sum+1)+n-1; else ans[u]=2*(n-1); } signed main() { n=g(),m=g(); for(R i=1,u,v;i<=m;++i) { u=g(),v=g(); if(u!=v) add(u,v),add(v,u); } tarjan(1); for(R i=1;i<=n;++i) printf("%lld\n",ans[i]); }
2019.04.12