1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define debug(x) cout << #x << " is " << x << endl
typedef long long ll;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f, N = 105, M = N * N;
int n, tot, num, res;
int ver[M], nxt[M], head[N];
int dfn[N], low[N], bridge[M];
void add(int x, int y) {
ver[++tot] = y, nxt[tot] = head[x], head[x] = tot;
}
void tarjan(int x, int inedge) {
dfn[x] = low[x] = ++num;
for (int i = head[x]; i ; i = nxt[i]) {
int y = ver[i];
if (!dfn[y]) {
tarjan(y, i);
low[x] = min(low[x], low[y]);
if (dfn[x] < low[y]) bridge[i] = bridge[i^1] = 1, res++;
}
else if (i != (inedge ^ 1)) low[x] = min(low[x], dfn[y]);
}
}
void init() {
tot = 1; num = res = 0;
memset(head, 0, sizeof(head));
memset(bridge, 0, sizeof(bridge));
memset(dfn, 0, sizeof(dfn));
memset(low, 0, sizeof(low));
}
int main()
{
while (~scanf("%d", &n)) {
init();
int x, y, num;
for (int i = 1; i <= n; ++i) {
scanf("%d (%d)", &x, &num);
while (num--) {
scanf("%d", &y);
if (y <= x) continue;
add(x, y); add(y, x);
}
}
for (int i = 0; i < n; ++i) if (!dfn[i]) tarjan(i, 0);
printf("%d critical links\n", res);
for (int i = 2; i < tot; i += 2) {
if (bridge[i])
printf("%d - %d\n", ver[i^1], ver[i]);
}
puts("");
}
return 0;
}
|