#include<vector> #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; typedef vector<int> vec; void Rd(int&res){ res=0;char c; while(c=getchar(),c<48); do res=res*10+(c&15); while(c=getchar(),c>47); } const int N=100001,M=500001; int n,m,tot_edge,head[N<<1]; struct Edge{ int to,nxt; }edge[M<<1]; void add_edge(int a,int b){ edge[tot_edge]=(Edge){b,head[a]}; head[a]=tot_edge++; } int tot,low[N],dfn[N],stk[N],top; vector<vec>blo; vec cut; void pack(int p,int to){ vec tmp=vec(1,p); for(;;){ int cur=stk[top];top--; tmp.push_back(cur); if(cur==to)break; } blo.push_back(tmp); } void Tarjan(int p){ low[p]=dfn[p]=++tot; stk[++top]=p; bool ok=false; int child=0; for(int i=head[p];~i;i=edge[i].nxt){ int to=edge[i].to; if(!dfn[to]){ Tarjan(to);child++; low[p]=min(low[p],low[to]); if(low[to]>=dfn[p]){ ok=true; pack(p,to); } }else low[p]=min(low[p],dfn[to]); } if(dfn[p]==1){ ok=child>1; if(!child)blo.push_back(vec(1,p)); } if(ok)cut.push_back(p); } int idx[N],cnt[N<<1],num[N<<1],fa[N<<1]; void dfs(int p,int f){ cnt[p]=num[p],fa[p]=f; for(int i=head[p];~i;i=edge[i].nxt){ int to=edge[i].to; if(to==f)continue; dfs(to,p); cnt[p]+=cnt[to]; } } ll ans[N]; int solve(){ for(int i=1;i<=n;i++)printf("%lld\n",ans[i]); return 0; } int main(){ Rd(n),Rd(m); memset(head,-1,sizeof(head)); for(int i=1,a,b;i<=m;i++){ Rd(a),Rd(b); add_edge(a,b); add_edge(b,a); } Tarjan(1); for(int i=0;i<cut.size();i++){ int p=cut[i]; idx[p]=blo.size()+i+1; } memset(head,-1,sizeof(head)),tot_edge=0; for(int i=0;i<blo.size();i++){ const vec& cur=blo[i]; vec tmp; for(int j=0;j<cur.size();j++){ int p=cur[j]; if(idx[p]){ add_edge(i+1,idx[p]); add_edge(idx[p],i+1); }else num[i+1]++; } } for(int i=0;i<cut.size();i++)num[idx[cut[i]]]=1; dfs(1,0); for(int i=1;i<=n;i++)ans[i]=n-1<<1; for(int i=0;i<cut.size();i++){ int p=cut[i],id=idx[p]; for(int j=head[id];~j;j=edge[j].nxt){ int to=edge[j].to; if(to==fa[id])continue; ans[p]+=1LL*cnt[to]*(n-1-cnt[to]); } int c=n-cnt[id]; ans[p]+=1LL*c*(n-1-c); } return solve(); }
|