(int a, int b)
| 174 | } |
| 175 | |
| 176 | public static int getLca(int a, int b) { |
| 177 | while (top[a] != top[b]) { |
| 178 | if (dep[top[a]] <= dep[top[b]]) { |
| 179 | b = fa[top[b]]; |
| 180 | } else { |
| 181 | a = fa[top[a]]; |
| 182 | } |
| 183 | } |
| 184 | return dep[a] <= dep[b] ? a : b; |
| 185 | } |
| 186 | |
| 187 | public static int getDist(int x, int y) { |
| 188 | return dist[x] + dist[y] - (dist[getLca(x, y)] << 1); |