QOJ.ac

QOJ

时间限制: 5 s 内存限制: 512 MB 总分: 100

#6591. Network Management

统计

Company M is a massive multinational corporation with branches and departments in many countries. To enable collaboration between its $N$ departments distributed around the world, the company has built a communication network connecting the entire organization. The structure of this network consists of $N$ routers and $N-1$ high-speed fiber-optic cables. Each department has its own dedicated router; all machines within a department's local area network connect to this router, which then communicates with other departments through this communication subnet. The network structure guarantees that there is a direct or indirect path between any two routers in the network for communication.

The data transmission speed of the high-speed fiber-optic cables is so fast that the latency caused by fiber-optic transmission can be ignored. However, due to router aging, data exchange on these routers introduces significant latency. The communication latency between two routers is related to the maximum exchange latency among all routers on the communication path between these two routers. As an intern in Company M's network department, you are now required to write a simple program to monitor the company's network status. The program must be able to update network status information (changes in router data exchange latency) at any time and, based on queries, provide the latency of the $k$-th largest router on the communication path between two routers.

Task

Your program should read the connection information for $N$ routers and $N-1$ fiber-optic cables, the initial data exchange latency $T_i$ for each router, and $Q$ queries (or status changes) from the input file. Process these $Q$ queries sequentially. They can be:

  1. Due to equipment updates or new equipment failures, the data exchange latency of a certain router has changed.
  2. Query the latency of the $k$-th largest router on the path between two routers $a$ and $b$.

Input

The first line of the input file contains two integers $N$ and $Q$, representing the total number of routers and the total number of queries, respectively.

The second line contains $N$ integers, where the $i$-th number represents the initial data latency $T_i$ of router $i$.

The following $N-1$ lines each contain two integers $x$ and $y$, representing a fiber-optic cable connecting router $x$ and router $y$.

Following this are $Q$ lines, each containing three integers $k, a, b$. If $k=0$, it indicates that the status of router $a$ has changed, and its data exchange latency becomes $b$. If $k>0$, it indicates a query for the latency of the $k$-th largest router among all routers (including $a$ and $b$) on the path from $a$ to $b$. Note that $a$ can be equal to $b$, in which case there is only one router on the path.

Output

For each query of the second type ($k>0$), output one line containing a single integer representing the corresponding latency. If there are fewer than $k$ routers on the path, output the message "invalid request!" (all lowercase, no quotes, with one space between the two words).

Examples

Input 1

5 5
5 1 2 3 4
3 1
2 1
4 3
5 3
2 4 5
0 1 2
2 2 3
2 1 4
3 3 5

Output 1

3
2
2
invalid request!

Constraints

For 100% of the test data, $N, Q \le 80,000$. Any router's latency is always less than $10^8$ at any time.

For all queries, $k \le N$.

40% of the test data satisfies that in all queries, the router's latency does not change.

10% of the test data satisfies $N, Q \le 1,000$.

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.