問題一覧 > 通常問題

No.2325 Skill Tree

レベル : / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 151
作問者 : dyktr_06 / テスター : tyawanmusi hikikomori sepa38 Seed57_cash
お気に入りにしたユーザー ProblemId : 9524 / 自分の提出
問題文最終更新日: 2023-05-27 04:10:00
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
MMA Contest 015 (順位表) の他の問題:

Problem Statement

Yakitori-kun is trying to teach skills to a slime.

There are $N$ skills that the slime can learn, named skill $1, 2, …, N$.

The slime already knows skill $1$. For $2 \leq i \leq N$, in order to learn skill $i$, the slime's level must be at least $L_i$ and the slime must already know skill $A_i$.

You are given $Q$ queries. Process them in order.

Each query is one of the following $2$ types.

  • 1 x: Print the maximum number of kinds of skills that a slime of level $x$ can learn.
  • 2 y: Print the minimum level required for the slime to learn skill $y$. If skill $y$ cannot be learned, print $-1$.

Constraints

  • $2 \leq N \leq 2 \times 10^5$
  • $1 \leq Q \leq 2 \times 10^5$
  • $1 \leq L_i \leq 10^9$
  • $1 \leq A_i \leq N$
  • $A_i \neq i$
  • $1 \leq x \leq 10^9$
  • $2 \leq y \leq N$
  • All inputs are integers.

Input

The input is given from standard input in the following format.

$N$   
$L_2$ $A_2$  
$L_3$ $A_3$  
$\vdots$

$L_N$ $A_N$  
$Q$  
query $1$  
query $2$  
$\vdots$

query $Q$

Each query is given in one of the following $2$ formats.

$1$ $x$
$2$ $y$

Output

Print $Q$ lines.

On the $j \: (1 \leq j \leq Q)$-th line, print the answer to the $j$-th query.

Sample

Sample 1
Input
5
5 1
10 1
8 3
38 4
7
1 1
1 8
1 10
2 2
2 3
2 4
2 5
Output
1
2
4
5
10
10
38

For the $1$-st query, the slime of level $1$ can learn skill $1$.

For the $2$-nd query, the slime of level $8$ can learn skills $1, 2$.

For the $3$-rd query, the slime of level $10$ can learn skills $1, 2, 3, 4$.

For the $6$-th query, in order to learn skill $4$, the slime must learn skills $1, 3$, and in order to learn skill $3$, its level must be at least $10$.

Sample

Sample 2
Input
4
10 4
10 2
10 3
5
1 1
1 10
2 2
2 3
2 4
Output
1
1
-1
-1
-1

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。