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

Method main

src/class185/Code05_OpenStore1.java:390–436  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

388 }
389
390 public static void main(String[] args) throws Exception {
391 FastReader in = new FastReader(System.in);
392 PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
393 n = in.nextInt();
394 m = in.nextInt();
395 A = in.nextInt();
396 for (int i = 1; i <= n; i++) {
397 age[i] = in.nextInt();
398 }
399 for (int i = 1, u, v, w; i < n; i++) {
400 u = in.nextInt();
401 v = in.nextInt();
402 w = in.nextInt();
403 addEdge(u, v, w);
404 addEdge(v, u, w);
405 }
406 // dfs1(1, 0, 0);
407 // dfs2(1, 1);
408 dfs3(1, 0, 0);
409 dfs4(1, 1);
410 centroidTree(getCentroid(1, 0), 0);
411 for (int i = 1; i <= n; i++) {
412 sort(curAge, curSum, curl[i], curr[i]);
413 for (int j = curl[i] + 1; j <= curr[i]; j++) {
414 curSum[j] += curSum[j - 1];
415 }
416 sort(faAge, faSum, fal[i], far[i]);
417 for (int j = fal[i] + 1; j <= far[i]; j++) {
418 faSum[j] += faSum[j - 1];
419 }
420 }
421 long lastAns = 0;
422 for (int i = 1, u, l, r; i <= m; i++) {
423 u = in.nextInt();
424 l = in.nextInt();
425 r = in.nextInt();
426 l = (int) ((lastAns + l) % A);
427 r = (int) ((lastAns + r) % A);
428 if (l > r) {
429 int tmp = l; l = r; r = tmp;
430 }
431 lastAns = compute(u, l, r);
432 out.println(lastAns);
433 }
434 out.flush();
435 out.close();
436 }
437
438 // 读写工具类
439 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
sortMethod · 0.95
computeMethod · 0.95
printlnMethod · 0.45
flushMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected