P3469 [POI2008]BLO-Blockade

 1 #include<iostream>
 2 #include<string>
 3 #include<queue>
 4 #include<stack>
 5 #include<vector>
 6 #include<map>
 7 #include<cstdio>
 8 #include<cstdlib>
 9 #include<algorithm>
10 #include<set>
11 #include<list>
12 #include<iomanip>
13 #include<cstring>
14 #include<cmath>
15 #include<limits>
16 using namespace std;
17 
18 #define au auto
19 #define debug(i) cout<<"<debug> "<<i<<"<\debug>"<<endl
20 #define mfor(i,a,b) for(register int i=(a);i<=(b);i++)
21 #define mrep(i,a,b) for(register int i=(a);i>=(b);i--)
22 #define LLL __int128
23 #define Re register
24 #define il inline
25 #define mem(a,b) memset(a,(b),sizeof(a))
26 typedef pair<int, int> intpair;
27 typedef long long int LL;
28 const int INF = 0x3f3f3f3f;
29 const long long int INFLL = 0x3f3f3f3f3f3f3f3f;
30 
31 int n, m;
32 int cnt;
33 const int maxn = 100010;
34 const int maxm = 1000010;
35 
36 struct Edge
37 {
38     int u, nxt;
39 }e[maxm];
40 
41 int head[maxn];
42 
43 void add(int a, int b)
44 {
45     e[++cnt].u = b;
46     e[cnt].nxt = head[a];
47     head[a] = cnt;
48 }
49 
50 int dfn[maxn];
51 int low[maxn];
52 int num[maxn];
53 LL ans[maxn];
54 bool cut[maxn];
55 int tot;
56 
57 void tarjan(int x)
58 {
59     dfn[x] = low[x] = ++tot;
60     num[x] = 1;
61     int cntf = 0;
62     LL sum = 0;
63     for (Re int i = head[x]; i != -1; i = e[i].nxt)
64     {
65         int u = e[i].u;
66         if (!dfn[u])
67         {
68             tarjan(u);
69             num[x] += num[u];
70             low[x] = min(low[x], low[u]);
71             if (low[u] >= dfn[x])
72             {
73                 ans[x] += (LL)num[u] * (n - (LL)num[u]);
74                 sum += num[u];
75                 cntf++;
76                 if (x > 1 || cntf > 1) cut[x] = true;
77             }
78         }
79         else low[x] = min(low[x], dfn[u]);
80     }
81     if (!cut[x]) ans[x] = 2 * (n - 1LL);
82     else ans[x] += (n - sum - 1) * (sum + 1) + n - 1;
83 }
84 
85 int main()
86 {
87     cin >> n >> m;
88     mem(head, -1);
89     mfor(i, 1, m)
90     {
91         int a, b;
92         cin >> a >> b;
93         add(a, b);
94         add(b, a);
95     }
96     tarjan(1);
97     mfor(i, 1, n) cout << ans[i] << endl;
98     return 0;
99 }
View Code

 

posted on 2019-10-20 21:04  thjkhdf12  阅读(109)  评论(0)    收藏  举报