| 474 | }; |
| 475 | |
| 476 | int main() { |
| 477 | ios_base::sync_with_stdio(false), cin.tie(nullptr); |
| 478 | |
| 479 | int N; cin >> N; |
| 480 | vector<top_tree_node> nodes(2*N-1); |
| 481 | for (int i = 0; i < 2 * N - 1; i++) { |
| 482 | nodes[i].__id = i; |
| 483 | } |
| 484 | |
| 485 | for (int i = 0; i < N; i++) { |
| 486 | top_tree_node* n = &nodes[i]; |
| 487 | n->is_path = n->is_vert = true; |
| 488 | n->update(); |
| 489 | } |
| 490 | |
| 491 | for (int e = 0; e < N-1; e++) { |
| 492 | int u, v; cin >> u >> v; u--, v--; |
| 493 | top_tree_node* a = &nodes[u]; |
| 494 | top_tree_node* b = &nodes[v]; |
| 495 | link(&nodes[N+e], a, b); |
| 496 | } |
| 497 | |
| 498 | int Q; cin >> Q; |
| 499 | while (Q--) { |
| 500 | int op; cin >> op; |
| 501 | if (op == 1) { |
| 502 | int u, v; cin >> u >> v; u--, v--; |
| 503 | auto sub = get_subtree(&nodes[u], &nodes[v]); |
| 504 | sub->do_subtree_increment(); |
| 505 | sub->downdate(); |
| 506 | sub->update_all(); |
| 507 | } else if (op == 2) { |
| 508 | int u, v; cin >> u >> v; u--, v--; |
| 509 | auto pth = get_path(&nodes[u], &nodes[v]); |
| 510 | pth->do_path_increment(); |
| 511 | pth->downdate(); |
| 512 | pth->update_all(); |
| 513 | } else if (op == 3) { |
| 514 | int v; cin >> v; v--; |
| 515 | nodes[v].make_root(); |
| 516 | cout << nodes[v].tot_ans[0] << '\n'; |
| 517 | } else assert(false); |
| 518 | |
| 519 | /* |
| 520 | cerr << "dumping tree" << '\n'; |
| 521 | for (int z = 0; z < 2*N-1; z++) { |
| 522 | cerr << "node " << z << '\n'; |
| 523 | cerr << "par: " << (nodes[z].p ? nodes[z].p->__id : -1) << '\n'; |
| 524 | cerr << "subtree_size: " << nodes[z].subtree_size << '\n'; |
| 525 | cerr << "path_size: " << nodes[z].path_size << '\n'; |
| 526 | cerr << "subtree_lazy: " << nodes[z].subtree_lazy << '\n'; |
| 527 | cerr << "path_lazy: " << nodes[z].path_lazy << '\n'; |
| 528 | cerr << "tot_A: " << nodes[z].tot_A << '\n'; |
| 529 | cerr << "own_A: " << nodes[z].own_A << '\n'; |
| 530 | cerr << "tot_sub_d[0]: " << nodes[z].tot_sub_d[0] << '\n'; |
| 531 | cerr << "tot_sub_d[1]: " << nodes[z].tot_sub_d[1] << '\n'; |
| 532 | cerr << "tot_ans[0]: " << nodes[z].tot_ans[0] << '\n'; |
| 533 | cerr << "tot_ans[1]: " << nodes[z].tot_ans[1] << '\n'; |
nothing calls this directly
no test coverage detected