1123: [POI2008]BLO

Description

Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通。

Input

输入n<=100000 m<=500000及m条边

Output

输出n个数,代表如果把第i个点去掉,将有多少对点不能互通。

Sample Input

5 5
1 2
2 3
1 3
3 4
4 5

Sample Output

8
8
16
14
8
 
这明显是求割点。。。tarjan之后记录子树大小,然后求点对即可。。
 1 #include<iostream>
 2 #include<cstdlib>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<algorithm>
 7 #include<string>
 8 #include<map>
 9 #include<queue>
10 #include<vector>
11 #include<set>
12 #define inf 1000000000
13 #define maxn 100000+5
14 #define maxm 1000000+5
15 #define eps 1e-10
16 #define ll long long
17 #define for0(i,n) for(int i=0;i<=(n);i++)
18 #define for1(i,n) for(int i=1;i<=(n);i++)
19 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
20 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
21 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go)
22 using namespace std;
23 int read(){
24     int x=0,f=1;char ch=getchar();
25     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
26     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
27     return x*f;
28 } 
29 int n,m,tot,ind;
30 int head[maxn],size[maxn],dfn[maxn],low[maxn];
31 ll ans[maxn];
32 struct edge{
33     int go,next;
34 }e[maxm];
35 void insert(int u,int v){
36     e[++tot]=(edge){v,head[u]};head[u]=tot;
37     e[++tot]=(edge){u,head[v]};head[v]=tot;
38 }
39 void tarjan(int x){
40     int t=0;
41     size[x]=1;
42     dfn[x]=low[x]=++ind;
43     for4(i,x)
44         if(dfn[y])low[x]=min(low[x],dfn[y]);
45         else{
46             tarjan(y);
47             size[x]+=size[y];
48             low[x]=min(low[x],low[y]);
49             if(dfn[x]<=low[y]){
50                 ans[x]+=(ll)t*size[y];
51                 t+=size[y];
52             }
53         }
54     ans[x]+=(ll)t*(n-t-1);
55 }
56 int main(){
57     //freopen("input.txt","r",stdin);
58     //freopen("output.txt","w",stdout);
59     n=read();m=read();
60     for1(i,m){
61         int u=read(),v=read();
62         insert(u,v);
63     }
64     tarjan(1);
65     for1(i,n)
66         printf("%lld\n",(ans[i]+n-1)*2);
67     return 0;
68 }
View Code

 

posted @ 2016-06-01 09:23  HTWX  阅读(116)  评论(0编辑  收藏  举报