题目大意:
给定一个无向图,有n个点,m条边,依次去掉每一个点(仅删掉这一个点)后,原图中的连通分量个数。
对于每个点记录它属于多少个bcc。
// #pragma GCC optimize(2)
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO \
ios::sync_with_stdio(false); \
// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 3e5 + 10;
const int maxm = 2e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 3;
const double eps = 1e-8;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
struct Edge
{
int next, to;
} e[maxn << 1];
int head[maxn], dfn[maxn], low[maxn], sta[maxn];
int bcc[maxn]; // 记录这个点属于多少个 BCC
int n, m, tim, k, top, cnt;
bool cut[maxn];
void add(int u, int v)
{
e[k].next = head[u];
e[k].to = v;
head[u] = k++;
}
void Tarjan(int u, int fa)
{
sta[++top] = u;
dfn[u] = low[u] = ++tim;
int child = 0;
bool flag = false;
for (int i = head[u]; i != -1; i = e[i].next)
{
int v = e[i].to;
if (v == fa)
continue;
if (!dfn[v])
{
child++;
Tarjan(v, u);
low[u] = min(low[u], low[v]);
if (low[v] >= dfn[u])
{
flag = true;
bcc[u]++;
while (top && sta[top] != u)
{
bcc[sta[top]]++;
// cout << sta[top] << endl;
top--;
}
}
}
else
low[u] = min(low[u], dfn[v]);
}
if (fa == 0)
{
if (child > 1)
cut[u] = true;
}
else if (flag)
cut[u] = true;
}
int main()
{
#ifdef WXY
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
IO;
int x, y;
memset(head, -1, sizeof head);
cin >> n >> m;
for (int i = 0; i < m; i++)
{
cin >> x >> y;
add(x, y);
add(y, x);
}
for (int i = 1; i <= n; i++)
{
if (!dfn[i])
{
cnt++;
Tarjan(i, 0);
}
}
for (int i = 1; i <= n; i++)
{
if (cut[i])
cout << cnt + bcc[i] - 1 << " ";
else if (head[i] != -1)
cout << cnt << " ";
else
cout << cnt - 1 << " ";
}
// cout << endl;
// while (top)
// {
// cout << "qwe " << sta[top] << endl;
// top--;
// }
return 0;
}