Logo
(追記) (追記ここまで)

33385번 - Fun on Tree 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
7 초 2048 MB222100.000%

문제

Beitou, renowned for its breathtaking beauty and abundant hot springs, attracts countless tourists seeking relaxation and rejuvenation. The region boasts an extraordinary concentration of hot springs and spas, making it a global hotspot for such indulgence. Once a quaint locale where locals sought solace in its natural hot springs, the Beitou Valley has blossomed into a sprawling expanse, now housing over thirty luxurious resorts.

Traditionally, hot springs evoke imagery of volcanic activity and the unmistakable scent of sulfur. However, for some, the latter proves rather unpleasant. You find yourself among those sensitive to the smell of sulfur, which brings us to your current predicament.

Presently visiting Beitou, you've obtained a map of this enchanting place, revealing a conceptual representation as a rooted tree. It's worth noting that Beitou's mystical aura allows for unconventional measurements, even enabling negative distances between nodes. Additionally, each node on the map comes with an associated sulfur content value.

An unexpected revelation leaves you questioning the accuracy of the sulfur content assigned to each location. In order to rectify this, your mission is to align the sulfur content with the newly acquired information. Moreover, you've uncovered intel about the location of the largest volcano in the vicinity. Prioritizing your safety and well-being, your ultimate goal is to pinpoint the spot farthest from this prominent volcano while having the lowest sulfur content. Your chosen evaluation metric for each node's viability is given by the formula $d_i - a_i,ドル wherein $d_i$ represents the distance between node $i$ and the largest volcano, and $a_i$ is the corresponding sulfur content value.

We can describe each piece of new information you acquire with three integers, $x_i,ドル $y_i,ドル and $v_i$. It means that all the subtree of $y_i$ now has $v_i$ more sulfur (if $v_i$ is negative, then the sulfur content value decreases). Besides, you also learn that the largest volcano is actually located at $x_i$.

Note that the modifications of sulfur value are persistent: when you get another piece of new information, the sulfur modifications from the previous ones still apply.

입력

The first line contains two integers $n$ and $q$ (2ドル \leq n \leq 2 \cdot 10^5$ and 0ドル \leq q \leq 2 \cdot 10^5$): the size of the tree and the number of queries.

The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($|a_i| \leq 10^9$): the sulfur content value of each nodes.

Next, $n-1$ lines are given. The $i$-th of these lines contains two integers $p_{i+1}$ and $w_{i+1}$ (1ドル \leq p_{i+1} \leq i$ and $|w_{i+1}| \leq 10^9$): the parent node of vertex $i+1$ and the distance between $p_{i+1}$ and $i+1$.

Finally, $q$ lines are given. Each line contains three integers $x_i,ドル $y_i,ドル and $v_i$ (1ドル \leq x_i, y_i \leq n$ and $|v_i| \leq 10^9$): the new piece of information you acquired.

출력

For each new piece of information, print a line with two integers $s_i$ and $d_i$: the index of the node having the largest viability and the viability itself.

If there are multiple answers, please output the one with the minimal node index.

제한

예제 입력 1

6 6
1 1 4 5 1 4
1 5
2 0
3 2
4 1
5 6
3 2 -100000
1 2 100000
1 1 0
2 2 66
3 1 5
4 4 -3

예제 출력 1

6 100005
6 10
6 10
1 4
1 -1
1 1

예제 입력 2

5 6
-10 0 2 -4 8
1 7
1 1
2 2
2 -2
1 1 100
2 1 -100
1 1 0
4 3 10
2 5 3
5 2 2

예제 출력 2

4 -87
1 17
4 13
1 19
1 17
1 15

예제 입력 3

6 3
0 0 0 0 0 0
1 10
1 10
1 -100
4 10
4 11
1 1 0
4 1 0
1 4 1000

예제 출력 3

2 10
6 11
2 10

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2023 > Day 6: olmrgcsi And His Friends’ Contest F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /