MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / pathMin

Method pathMin

src/class194/Code08_Tourists1.java:198–219  ·  view source on GitHub ↗
(int x, int y)

Source from the content-addressed store, hash-verified

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);

Callers 1

mainMethod · 0.95

Calls 1

queryMethod · 0.95

Tested by

no test coverage detected