(int a, int b)
| 260 | } |
| 261 | |
| 262 | public static int getLca(int a, int b) { |
| 263 | while (top[a] != top[b]) { |
| 264 | if (dep[top[a]] <= dep[top[b]]) { |
| 265 | b = fa[top[b]]; |
| 266 | } else { |
| 267 | a = fa[top[a]]; |
| 268 | } |
| 269 | } |
| 270 | return dep[a] <= dep[b] ? a : b; |
| 271 | } |
| 272 | |
| 273 | public static int getDist(int x, int y) { |
| 274 | return dep[x] + dep[y] - (dep[getLca(x, y)] << 1); |