You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.7 KiB

#include <bits/stdc++.h>
using namespace std;
const int N = 1010, M = 1010;
int n, m;
int dfn[N], low[N], stk[N], ts, top, root;
int bcnt;
vector<int> bcc[N];
bool cut[N];
int e[M], h[N], idx, w[M], ne[M];
void add(int a, int b, int c = 0) {
e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++;
}
void tarjan(int u, int fa) {
low[u] = dfn[u] = ++ts;
stk[++top] = u;
int son = 0;
for (int i = h[u]; ~i; i = ne[i]) {
int v = e[i];
if (v == fa) continue;
if (!dfn[v]) {
son++;
tarjan(v, u);
low[u] = min(low[u], low[v]);
if (low[v] >= dfn[u]) {
int x;
if (u != root || son > 1) cut[u] = 1;
bcnt++;
do {
x = stk[top--];
bcc[bcnt].push_back(x);
} while (x != v);
bcc[bcnt].push_back(u);
}
} else
low[u] = min(low[u], dfn[v]);
}
if (fa == -1 && son == 0) bcc[++bcnt].push_back(u);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("396_Prepare.in", "r", stdin);
#endif
memset(h, -1, sizeof h);
scanf("%d", &m);
while (m--) {
int a, b;
scanf("%d %d", &a, &b);
n = max(n, a), n = max(n, b); // 鄙视一下~
if (a != b) add(a, b), add(b, a);
}
for (root = 1; root <= n; root++)
if (!dfn[root]) tarjan(root, -1);
cout << "点双个数:" << bcnt << endl;
for (int i = 1; i <= bcnt; i++) {
cout << "点双编号:" << i << ", 内部节点:";
for (int j = 0; j < bcc[i].size(); j++)
cout << bcc[i][j] << " ";
cout << endl;
}
return 0;
}