| 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 { |