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.
78 lines
1.8 KiB
78 lines
1.8 KiB
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
const int N = 5010, M = 20010;
|
|
|
|
int n, m;
|
|
int d[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++;
|
|
}
|
|
|
|
int dfn[N], low[N], ts, stk[N], top, root;
|
|
vector<int> bcc[N];
|
|
int id[N], bcnt;
|
|
int is_bridge[M];
|
|
|
|
void tarjan(int u, int fa) {
|
|
dfn[u] = low[u] = ++ts;
|
|
stk[++top] = u;
|
|
for (int i = h[u]; ~i; i = ne[i]) {
|
|
int v = e[i];
|
|
if (!dfn[v]) {
|
|
tarjan(v, i);
|
|
low[u] = min(low[u], low[v]);
|
|
if (dfn[u] < low[v]) is_bridge[i] = is_bridge[i ^ 1] = 1;
|
|
} else if (i != (fa ^ 1))
|
|
low[u] = min(low[u], dfn[v]);
|
|
}
|
|
|
|
if (dfn[u] == low[u]) {
|
|
++bcnt;
|
|
int x;
|
|
do {
|
|
x = stk[top--];
|
|
id[x] = bcnt;
|
|
bcc[bcnt].push_back(x);
|
|
} while (x != u);
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
#ifndef ONLINE_JUDGE
|
|
freopen("395.in", "r", stdin);
|
|
#endif
|
|
memset(h, -1, sizeof h);
|
|
scanf("%d %d", &n, &m);
|
|
while (m--) {
|
|
int a, b;
|
|
scanf("%d %d", &a, &b);
|
|
if (a != b) add(a, b), add(b, a);
|
|
}
|
|
|
|
for (root = 1; root <= n; root++)
|
|
if (!dfn[root]) tarjan(root, -1);
|
|
|
|
cout << "bcnt=" << bcnt << endl;
|
|
|
|
for (int u = 1; u <= n; u++)
|
|
for (int i = h[u]; ~i; i = ne[i]) {
|
|
int v = e[i];
|
|
|
|
if (is_bridge[i]) {
|
|
cout << "is_bridge=" << u << "->" << v << ",id[" << v << "]=" << id[v] << endl;
|
|
d[id[v]]++;
|
|
}
|
|
}
|
|
|
|
for (int i = 1; i <= bcnt; i++)
|
|
// if (d[i] == 1) cout << i << " ";
|
|
{
|
|
cout << "i=" << i << ",d[" << i << "]=" << d[i] << endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|