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

Method main

src/class185/Code04_Fantasy1.java:295–321  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

293 }
294
295 public static void main(String[] args) throws Exception {
296 FastReader in = new FastReader(System.in);
297 PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
298 n = in.nextInt();
299 m = in.nextInt();
300 for (int i = 1, u, v, w; i < n; i++) {
301 u = in.nextInt();
302 v = in.nextInt();
303 w = in.nextInt();
304 addEdge(u, v, w);
305 addEdge(v, u, w);
306 }
307 // dfs1(1, 0, 0);
308 // dfs2(1, 1);
309 dfs3(1, 0, 0);
310 dfs4(1, 1);
311 int root = getCentroid(1, 0);
312 centroidTree(root, 0);
313 for (int i = 1, x, v; i <= m; i++) {
314 x = in.nextInt();
315 v = in.nextInt();
316 add(x, v);
317 out.println(compute(root));
318 }
319 out.flush();
320 out.close();
321 }
322
323 // 读写工具类
324 static class FastReader {

Callers

nothing calls this directly

Calls 11

nextIntMethod · 0.95
addEdgeMethod · 0.95
dfs3Method · 0.95
dfs4Method · 0.95
getCentroidMethod · 0.95
centroidTreeMethod · 0.95
addMethod · 0.95
computeMethod · 0.95
printlnMethod · 0.45
flushMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected