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

Method query

src/class185/Code04_Fantasy1.java:273–282  ·  view source on GitHub ↗
(int x)

Source from the content-addressed store, hash-verified

271 }
272
273 public static long query(int x) {
274 long ans = addCost[x];
275 for (int cur = x, fa = centfa[cur]; fa > 0; cur = fa, fa = centfa[cur]) {
276 int dist = getDist(x, fa);
277 ans += addCost[fa];
278 ans -= minusCost[cur];
279 ans += (sum[fa] - sum[cur]) * dist;
280 }
281 return ans;
282 }
283
284 public static long compute(int u) {
285 long ans = query(u);

Callers 1

computeMethod · 0.95

Calls 1

getDistMethod · 0.95

Tested by

no test coverage detected