guide of the maze shapes a tree with n rooms numbered from 1 to n and n−1 burrows associating them to such an extent that it is feasible to go between each pair of rooms through a few passages. The I-th room (1≤i≤n) has simulated intelligence hallucination rate. To go from the x-th space to the y-th room, there should exist a passage among x and y, and it takes max(|ax+ay|,|ax−ay|) energy. |z| means the outright

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Correct answer only. Else i will dislike.

 

The guide of the maze shapes a tree with n rooms numbered from 1 to n and n−1 burrows associating them to such an extent that it is feasible to go between each pair of rooms through a few passages. The I-th room (1≤i≤n) has simulated intelligence hallucination rate. To go from the x-th space to the y-th room, there should exist a passage among x and y, and it takes max(|ax+ay|,|ax−ay|) energy. |z| means the outright worth of z. To forestall grave looters, the labyrinth can change the hallucination pace of any room in it. Chanek and Indiana would ask q inquiries. There are two kinds of inquiries to be finished: 1 u c — The figment pace of the x-th room is changed to c (1≤u≤n, 0≤|c|≤109). 2 u v — Chanek and Indiana ask you the base amount of energy expected to take the mysterious fortune at room v in case they are at first at room u (1≤u,v≤n). Help them, so you can get a part of the fortune! 

Input :The primary line contains two integers n and q (2≤n≤105, 1≤q≤105) — the number of rooms in the labyrinth and the number of inquiries. The subsequent line contains n integers a1,a2,… ,an (0≤|ai|≤109) — inital dream pace of each room. The I-th of the following n−1 lines contains two integers si and ti (1≤si,ti≤n), which means there is a passage interfacing si-th room and ti-th room. The given edges structure a tree. The following q lines contain the question as portrayed. The given inquiries are legitimate. 

Output :For each sort 2 question, output a line containing an integer — the base amount of energy required for Chanek and Indiana to take the mysterious fortune.

Expert Solution
steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY