0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 14:56:27 +00:00

P3469 [POI2008]BLO-Blockade

https://www.luogu.com.cn/record/87072207
This commit is contained in:
Baoshuo Ren 2022-09-20 21:38:15 +08:00
parent b238b8ee8b
commit ff6dda0aec
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

77
Luogu/P3469/P3469.cpp Normal file
View File

@ -0,0 +1,77 @@
#include <iostream>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int n, m;
long long ans[N];
std::vector<int> g[N];
int root, cnt, dfn[N], low[N], siz[N];
bool cut[N];
void tarjan(int u) {
dfn[u] = low[u] = ++cnt;
siz[u] = 1;
bool flag = false;
int sum = 0;
for (int v : g[u]) {
if (!dfn[v]) {
tarjan(v);
low[u] = std::min(low[u], low[v]);
siz[u] += siz[v];
if (dfn[u] <= low[v]) {
if (u != root || flag) {
cut[u] = true;
sum += siz[v];
ans[u] += static_cast<long long>(n - siz[v]) * siz[v];
} else {
flag = true;
}
}
} else {
low[u] = std::min(low[u], dfn[v]);
}
}
if (cut[u]) {
ans[u] += static_cast<long long>(n - sum - 1) * (sum + 1)
+ n - 1;
} else {
ans[u] = 2 * (n - 1);
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1, u, v; i <= m; i++) {
cin >> u >> v;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
for (int i = 1; i <= n; i++) {
if (!dfn[i]) {
root = i;
tarjan(i);
}
}
for (int i = 1; i <= n; i++) {
cout << ans[i] << endl;
}
return 0;
}