-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBridgeNum.java
65 lines (62 loc) · 1.66 KB
/
BridgeNum.java
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
63
64
65
import java.util.*;
import static java.lang.Math.min;
public class BridgeNum {
static int time;
static int[] tin;
static int[] fup;
static boolean[] used;
static int cal;
static List<List<Integer>> grath;
static void gdf(int v, int... ps) {
int p;
if (ps.length == 0) {
p = -1;
} else {
p = ps[0];
}
used[v] = true;
tin[v] = fup[v] = time++;
for (int i = 0; i < grath.get(v).size(); i++) {
int to = grath.get(v).get(i);
if (to == p) continue;
if (used[to])
fup[v] = min(fup[v], tin[to]);
else {
gdf(to, v);
fup[v] = min(fup[v], fup[to]);
if (fup[to] > tin[v])
cal++;
}
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int numv = in.nextInt();
in.nextLine();
int numr = in.nextInt();
in.nextLine();
grath = new ArrayList<>();
for (int i = 0; i < numv; i++) {
grath.add(new ArrayList<>());
}
for (int i = 0; i < numr; i++) {
var a = in.nextInt();
var b = in.nextInt();
in.nextLine();
grath.get(a).add(b);
grath.get(b).add(a);
}
time = 0;
cal = 0;
tin = new int[numv];
fup = new int[numv];
used = new boolean[numv];
for (int i = 0; i < numv; i++) {
used[i] = false;
}
for (int i = 0; i < numv; i++){
gdf(i);
}
System.out.println(cal);
}
}