#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 N+1N+1 planets, indexed from 00 to NN, where Earth has index NN. Every planet has a unique population count (P[i]P[i] for the ii-th planet, i{0,,N}i \in\{0, \ldots, N\}). The planets are connected with NN bidirectional portals in such a way that you can travel between any two planets using only these portals. Portal ii (i{0,,N1}i \in\{0, \ldots, N-1\}) connects planets U[i]U[i] and V[i]V[i]. 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 KK other planets - A[0],A[1],A[0], A[1], \ldots, A[K1]A[K-1]. 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 SS be the set of all visited planets.

Now the aliens decided to test whether Earth is worthy to join their supercivilization by asking you QQ questions of two types.

  • Type 11: What is the size of the set SS?
  • Type 22: They pick a planet xx from SS, a distance dd, and a number rr. They ask you what is the rr-th smallest planet by population count among the planets at distance dd from xx. (For instance, if r=1r=1, this is the planet with the least population count. This planet can, but does not have to belong to the set SS.).

There is exactly one query of type 11.

Input format

Line 1: N,K,QN, K, Q.

Line 2: P[0],,P[N]P[0], \ldots, P[N].

Line 3: A[0],,A[K1]A[0], \ldots, A[K-1].

The ii-th (i{0,,N1})(i \in\{0, \ldots, N-1\}) of the following NN lines: U[i]U[i] and V[i]V[i].

The following QQ lines satisfy one of these formats:

  • 11 (a query of type 11)
  • 2xdr2\,x\,d\,r (a query of type 22)

Output

For every query print the answer in one line. Either the number of planets visited during the excursion, or the rr-th planet by population from the planets at distance dd from xx.

Input bounds

  • $1 \leq N \leq 100000 ; 1 \leq K \leq 10 ; 1 \leq Q \leq 100000$.
  • for 0iN0 \leq i \leq N it holds 1P[i]1091 \leq P[i] \leq 10^{9}. All P[i]P[i] are unique.
  • for 0iK10 \leq i \leq K-1 it holds 0A[i]N10 \leq A[i] \leq N-1.
  • for 0iN10 \leq i \leq N-1 it holds 0U[i],V[i]N0 \leq U[i], V[i] \leq N
  • The KK planets of origin and the planet Earth have exactly one portal connected to them.
  • For each query, a value 1t21 \leq t \leq 2 is given. When t=2t=2, additional values x,dx, d and rr are given. It holds that xS,d1x \in S, d \geq 1, and r1r \geq 1.
  • It is guaranteed that there are at least rr planets at a distance dd from planet xx.

Subtasks

  1. (3 points) Q=1Q=1.
  2. (14 points) N2000,Q2000N \leq 2000, Q \leq 2000.
  3. (21 points) K=1K=1.
  4. (12 points) N10000N \leq 10000.
  5. (13 points) Q10000Q \leq 10000.
  6. (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 S={1,3,4,5}S=\{1,3,4,5\} during the excursion. The queries of type 22 are:

  • x=4,d=2,r=1x=4, d=2, r=1
  • At distance 22 from planet 44, there is only the planet 11.
  • x=3,d=2,r=1x=3, d=2, r=1
  • At distance 22 from planet 33, there are planets 0,2,0,2, and 55. Among them, planet 00 has the lowest population count.
  • x=4,d=1,r=3x=4, d=1, r=3
  • At distance 11 from planet 44, there are the planets 0,2,3,0,2,3, and 55, and their order by population is 3,0,2,53,0,2,5. The third among them is planet 22.
  • x=5,d=2,r=3x=5, d=2, r=3
  • At distance 22 from planet 55, there are planets 0,2,0,2, and 33, and their order by population is 3,0,23,0,2. The third among them is planet 22.
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