#HK4110. 「BalkanOI 2023 Day2」Aliens
「BalkanOI 2023 Day2」Aliens
Description
Maribor has just been visited by aliens! They share with you their technology and their history.
There are planets, indexed from to , where Earth has index . Every planet has a unique population count ( for the -th planet, ). The planets are connected with bidirectional portals in such a way that you can travel between any two planets using only these portals. Portal () connects planets and . The distance between two planets is the least number of portals required to travel between them.
You start from Earth and want to make excursion and visit other planets - , . These are called planets of origin. You also know that each planet of origin and Earth have only one portal connected to it. Your excursion is a shortest route that starts from Earth and visits all planets of origin and also all the planets along the way. Let be the set of all visited planets.
Now the aliens decided to test whether Earth is worthy to join their supercivilization by asking you questions of two types.
- Type : What is the size of the set ?
- Type : They pick a planet from , a distance , and a number . They ask you what is the -th smallest planet by population count among the planets at distance from . (For instance, if , this is the planet with the least population count. This planet can, but does not have to belong to the set .).
There is exactly one query of type .
Input format
Line 1: .
Line 2: .
Line 3: .
The -th of the following lines: and .
The following lines satisfy one of these formats:
- (a query of type )
- (a query of type )
Output
For every query print the answer in one line. Either the number of planets visited during the excursion, or the -th planet by population from the planets at distance from .
Input bounds
- $1 \leq N \leq 100000 ; 1 \leq K \leq 10 ; 1 \leq Q \leq 100000$.
- for it holds . All are unique.
- for it holds .
- for it holds
- The planets of origin and the planet Earth have exactly one portal connected to them.
- For each query, a value is given. When , additional values and are given. It holds that , and .
- It is guaranteed that there are at least planets at a distance from planet .
Subtasks
- (3 points) .
- (14 points) .
- (21 points) .
- (12 points) .
- (13 points) .
- (37 points) No additional constraints.
5 1 5
8 7 9 4 16 12
1
0 4
3 1
2 4
5 4
4 3
1
2 4 2 1
2 3 2 1
2 4 1 3
2 5 2 3
4
1
0
2
2

There is one planet of origin, and we visit the planets during the excursion. The queries of type are:
- At distance from planet , there is only the planet .
- At distance from planet , there are planets and . Among them, planet has the lowest population count.
- At distance from planet , there are the planets and , and their order by population is . The third among them is planet .
- At distance from planet , there are planets and , and their order by population is . The third among them is planet .
10 2 11
1 2 3 4 5 6 7 8 9 10 11
9 3
5 8
2 7
3 4
6 8
0 1
2 9
5 2
4 5
7 10
1 2
1
2 5 1 2
2 5 2 2
2 5 2 3
2 5 2 4
2 9 3 2
2 9 3 3
2 9 4 1
2 2 1 3
2 2 2 4
2 2 3 1
7
4
3
6
7
4
8
3
7
10
3
