Coherence

Time limit: 3.25s Memory limit: 512MB Input: Output:

You are the supervisor of a super-secret government operation, where coordination is key, and everything will go wrong otherwise. You are in charge of NN workers, numbered from 11 to NN, each of which have the ability to directly communicate with some other workers. These worker relations can be viewed as a tree (connected undirected acyclic graph), where each node represents one of the workers, and each edge represents one of the direct two-sided communication channels between two workers. This relation tree has a special property, namely that, in order to maximize work efficiency, each worker has at most 2020 direct communication channels with any other workers. This way, each of the NN workers can directly or indirectly communicate with each other, via a series of direct communications.

The government officials working on a complex top secret operation..\text{The government officials working on a complex top secret operation.}.

Task

You, as the supervisor, have to handle QQ events of the following types:

  • As a result of a mutual agreement, worker AA and worker BB decide to switch roles in order to prevent burnout. More exactly, they will switch places in the network. As a result, worker AA will now work with worker BB's former direct colleagues, and worker BB will now work with worker AA's former direct colleagues.
  • You know that, in order to complete the next phase of the operation, you need at least KK workers working in tandem. As such, in order to maximize the efficiency of the operation, you want to use as little workers as possible. Realizing that this might be a tideous task, you settle for finding the minimal prefix of workers {1,2,,P}\{1, 2, \dots, P\}, such that each worker in {1,2,,P}\{1, 2, \dots, P\} can collaborate with any other worker in {1,2,,P}\{1, 2, \dots, P\}, communicating only through workers in {1,2,,P}\{1, 2, \dots, P\}, thus being able to complete the phase successfully. More formally, we want to find the minimum PKP \geq K, such that the induced subgraph made up of nodes in the range [1,P][1, P] is connected.

Input data

The input file consists of:

  • a line containing integer NN.
  • N1N-1 lines, the ii-th of which consisting of the 22 integers aa and bb, representing an edge between nodes aa and bb.
  • a line containing integer QQ.
  • QQ lines, of the format 1 a b1\ a\ b, or 2 k2\ k, depending on the type of the event.

Output data

The output file must contain the answer for each event of type 22, on a single line each.

Constraints and clarifications

  • 1N300 0001 \le N \le 300 \ 000.
  • 1Q300 0001 \le Q \le 300 \ 000.
  • 1a,bN1 \le a, b \le N for all edges, and events of type 11.
  • 1kN1 \le k \le N for all events of type 22.
  • An induced subgraph of graph G(V,E)G(V,E) is a graph G(V,E)G'(V',E'), such that VVV' \subseteq V, EEE' \subseteq E and (a,b)E\forall (a, b) \in E', it holds that a,bVa, b \in V'.|
# Score Constraints
1 0 Examples
2 10 N1 000,Q1 000N \le 1 \ 000, Q \le 1 \ 000.
3 15 N100 000,Q100 000N \le 100 \ 000, Q \le 100 \ 000, there are no updates.
4 20 N100 000,Q100 000N \le 100 \ 000, Q \le 100 \ 000, the tree is a line of the form abca - b - c - \dots.
5 22 N100 000,Q100 000N \le 100 \ 000, Q \le 100 \ 000
6 33 No additional restrictions

Example

stdin

11
1 2
1 3
2 10
2 11
3 4
3 5
3 6
5 7
6 8
6 9
12
2 1
2 5
2 3
1 3 5
2 1
2 2
1 1 11
2 1
2 2
2 3
2 4
2 5

stdout

1
5
3
1
2
1
2
11
11
11

Explanation

For simplicity, we'll denote the induced subgraph made up of nodes {1,2,,P}\{1, 2, \dots, P\} as G(P)G(P).

For the first three events of type 22, the tree looks like this.

As can be observed, G(P)G(P) is connected for all PP in [1,N][1, N]. As such, for all queries, the minimum PKP \geq K is KK.

For the next two events of type 22, the tree looks like this.

For K=1K = 1, the minimal prefix subgraph is G(1)G(1), which is connected.

For K=2K = 2, the minimal prefix subgraph is G(2)G(2), which is connected.

For the next five events of type 22, the tree looks like this.

For K=1K = 1, the minimal prefix subgraph is G(1)G(1), which is connected.

For K=2K = 2, the minimal prefix subgraph is G(2)G(2), which is connected.

For K=3K = 3, the minimal prefix subgraph is G(11)G(11), which is connected.

For K=4K = 4, the minimal prefix subgraph is G(11)G(11), which is connected.

For K=5K = 5, the minimal prefix subgraph is G(11)G(11), which is connected.

Log in or sign up to be able to send submissions!