| 196 | } |
| 197 | |
| 198 | public static int pathMin(int x, int y) { |
| 199 | int ans = INF; |
| 200 | while (top[x] != top[y]) { |
| 201 | if (dep[top[x]] < dep[top[y]]) { |
| 202 | int tmp = x; |
| 203 | x = y; |
| 204 | y = tmp; |
| 205 | } |
| 206 | ans = Math.min(ans, query(nid[top[x]], nid[x], 1, cnti, 1)); |
| 207 | x = fa[top[x]]; |
| 208 | } |
| 209 | if (dep[x] < dep[y]) { |
| 210 | int tmp = x; |
| 211 | x = y; |
| 212 | y = tmp; |
| 213 | } |
| 214 | ans = Math.min(ans, query(nid[y], nid[x], 1, cnti, 1)); |
| 215 | if (y > n) { |
| 216 | ans = Math.min(ans, arr[fa[y]]); |
| 217 | } |
| 218 | return ans; |
| 219 | } |
| 220 | |
| 221 | public static void main(String[] args) throws Exception { |
| 222 | FastReader in = new FastReader(System.in); |