QOJ.ac

QOJ

Limite de temps : 4 s Limite de mémoire : 512 MB Points totaux : 100

#7460. rla1rmdq

Statistiques

Given a tree with $n$ nodes and weighted edges, and a sequence $a$ of length $n$.

Define the parent of node $x$ as $fa(x)$, and the root $rt$ satisfies $fa(rt)=rt$.

Define the depth $dep(x)$ of node $x$ as the sum of edge weights on the simple path from $x$ to the root.

There are $m$ operations:

1 l r: For $l \le i \le r$, update $a_i := fa(a_i)$.

2 l r: Query the minimum $dep(a_i)$ for $l \le i \le r$.

Input

The first line contains three space-separated integers $n$, $m$, and $rt$, where $rt$ is the index of the root node.

The next $n-1$ lines each contain three space-separated integers $u, v, w$, representing an edge between $u$ and $v$ with weight $w$.

The next line contains $n$ space-separated integers representing the sequence.

The next $m$ lines each contain three space-separated integers, representing an operation.

Output

For each operation of type 2, output one integer per line representing the answer.

Examples

Input 1

5 6 2
3 2 2
5 3 3
1 2 4
4 2 3
3 3 3 1 2
2 1 1
2 2 3
2 4 5
1 2 3
1 4 4
2 1 2

Output 1

2
2
0
0

Subtasks

Idea: yummy, Solution: nzhtl1477&memset0, Code: nzhtl1477, Data: nzhtl1477

For $100\%$ of the data, $1\le n,m\le 2\cdot 10^5$, $1\le a_i\le n$, and edge weights are in the range $[0, 10^9]$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.