(int x, int k)
| 169 | } |
| 170 | |
| 171 | public static int kthAncestor(int x, int k) { |
| 172 | for (int p = 0; p < MAXP; p++) { |
| 173 | if (((k >> p) & 1) != 0) { |
| 174 | x = stjump[x][p]; |
| 175 | } |
| 176 | } |
| 177 | return x; |
| 178 | } |
| 179 | |
| 180 | public static int nearest(int x, int y) { |
| 181 | if (isAncestor(y, x)) { |