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

Method main

src/class185/Code01_Wave1.java:318–357  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

316 }
317
318 public static void main(String[] args) throws Exception {
319 FastReader in = new FastReader(System.in);
320 PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
321 n = in.nextInt();
322 m = in.nextInt();
323 for (int i = 1; i <= n; i++) {
324 arr[i] = in.nextInt();
325 }
326 for (int i = 1, u, v; i < n; i++) {
327 u = in.nextInt();
328 v = in.nextInt();
329 addEdge(u, v);
330 addEdge(v, u);
331 }
332 // dfs1(1, 0);
333 // dfs2(1, 1);
334 dfs3(1, 0);
335 dfs4(1, 1);
336 centroidTree(getCentroid(1, 0), 0);
337 for (int i = 1; i <= n; i++) {
338 add(i, arr[i]);
339 }
340 int lastAns = 0;
341 for (int i = 1, op, x, y; i <= m; i++) {
342 op = in.nextInt();
343 x = in.nextInt();
344 y = in.nextInt();
345 x ^= lastAns;
346 y ^= lastAns;
347 if (op == 0) {
348 lastAns = query(x, y);
349 out.println(lastAns);
350 } else {
351 add(x, y - arr[x]);
352 arr[x] = y;
353 }
354 }
355 out.flush();
356 out.close();
357 }
358
359 // 读写工具类
360 static class FastReader {

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected