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

Method prepare

src/class185/Code07_HideSeek1.java:350–372  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

348 }
349
350 public static void prepare() {
351 for (int i = 1; i <= n; i++) {
352 black[i] = true;
353 }
354 for (int i = 1; i <= n; i++) {
355 distFa[i] = new Set();
356 sonMax[i] = new Set();
357 }
358 for (int i = 1; i <= n; i++) {
359 for (int u = i, fa = centfa[u]; fa > 0; u = fa, fa = centfa[u]) {
360 distFa[u].add(getDist(i, fa));
361 }
362 }
363 for (int i = 1; i <= n; i++) {
364 sonMax[i].add(0);
365 if (centfa[i] > 0) {
366 sonMax[centfa[i]].add(distFa[i].first());
367 }
368 }
369 for (int i = 1; i <= n; i++) {
370 addAns(i);
371 }
372 }
373
374 public static void main(String[] args) throws Exception {
375 FastReader in = new FastReader();

Callers 1

mainMethod · 0.95

Calls 4

getDistMethod · 0.95
addAnsMethod · 0.95
firstMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected