标签:信息 roo || poi set 个数 删掉 str mat
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define ll long long
using namespace std;
inline int read(){
int x=0,o=1;char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')o=-1,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*o;
}
const int N=100005;
const int M=500005;
int tot,head[N],nxt[M*2],to[M*2];
int n,m,top,sum,timeclock,root;
int size[N],dfn[N],low[N],cut[N];
ll ans[N];
inline void add(int a,int b){
nxt[++tot]=head[a];head[a]=tot;to[tot]=b;
}
inline void tarjan(int u){
dfn[u]=low[u]=++timeclock;
int child=0,sum=0;size[u]=1;
for(int i=head[u];i;i=nxt[i]){
int v=to[i];
if(!dfn[v]){
tarjan(v);
size[u]+=size[v];
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u]){
ans[u]+=(ll)size[v]*(n-size[v]);
sum+=size[v];
++child;
if(u!=root||child>=2)cut[u]=1;
}
}
else low[u]=min(low[u],dfn[v]);
}
if(!cut[u])ans[u]=2*(n-1);
else ans[u]+=(ll)(n-sum-1)*(sum+1)+(n-1);
}
int main(){
n=read(),m=read();
for(int i=1;i<=m;++i){
int a=read(),b=read();
add(a,b);add(b,a);
}
tarjan(1);
for(int i=1;i<=n;++i)printf("%lld\n",ans[i]);
return 0;
}
标签:信息 roo || poi set 个数 删掉 str mat
原文地址:https://www.cnblogs.com/PPXppx/p/11378810.html