(String[] args)
| 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 { |
nothing calls this directly
no test coverage detected