()
| 34 | public static int[] root = new int[MAXN]; |
| 35 | |
| 36 | public static void prepare() { |
| 37 | dist[0] = -1; |
| 38 | for (int i = 1; i <= n; i++) { |
| 39 | up[i] = ls[i] = rs[i] = dist[i] = 0; |
| 40 | father[i] = i; |
| 41 | // 初始每个集合i只有元素i |
| 42 | root[i] = i; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | public static int find(int i) { |
| 47 | father[i] = father[i] == i ? i : find(father[i]); |