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

Method add

src/class185/Code04_Fantasy1.java:263–271  ·  view source on GitHub ↗
(int x, int v)

Source from the content-addressed store, hash-verified

261 }
262
263 public static void add(int x, int v) {
264 sum[x] += v;
265 for (int cur = x, fa = centfa[cur]; fa > 0; cur = fa, fa = centfa[cur]) {
266 int dist = getDist(x, fa);
267 sum[fa] += v;
268 addCost[fa] += 1L * v * dist;
269 minusCost[cur] += 1L * v * dist;
270 }
271 }
272
273 public static long query(int x) {
274 long ans = addCost[x];

Callers 1

mainMethod · 0.95

Calls 1

getDistMethod · 0.95

Tested by

no test coverage detected