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

Method main

src/class185/Code07_HideSeek1.java:374–415  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

372 }
373
374 public static void main(String[] args) throws Exception {
375 FastReader in = new FastReader();
376 PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
377 n = in.nextInt();
378 for (int i = 1, u, v; i < n; i++) {
379 u = in.nextInt();
380 v = in.nextInt();
381 addEdge(u, v);
382 addEdge(v, u);
383 }
384 // dfs1(1, 0);
385 // dfs2(1, 1);
386 dfs3(1, 0);
387 dfs4(1, 1);
388 centroidTree(getCentroid(1, 0), 0);
389 prepare();
390 m = in.nextInt();
391 int blackCnt = n;
392 char op;
393 for (int i = 1, x; i <= m; i++) {
394 op = in.nextChar();
395 if (op == 'C') {
396 x = in.nextInt();
397 black[x] = !black[x];
398 if (black[x]) {
399 off(x);
400 blackCnt++;
401 } else {
402 on(x);
403 blackCnt--;
404 }
405 } else {
406 if (blackCnt <= 1) {
407 out.println(blackCnt - 1);
408 } else {
409 out.println(maxDist.first());
410 }
411 }
412 }
413 out.flush();
414 out.close();
415 }
416
417 // 读写工具类
418 static class FastReader {

Callers

nothing calls this directly

Calls 14

nextIntMethod · 0.95
addEdgeMethod · 0.95
dfs3Method · 0.95
dfs4Method · 0.95
centroidTreeMethod · 0.95
getCentroidMethod · 0.95
prepareMethod · 0.95
nextCharMethod · 0.95
offMethod · 0.95
onMethod · 0.95
firstMethod · 0.80
printlnMethod · 0.45

Tested by

no test coverage detected