CF1583H.Omkar and Tours

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Omkar is hosting tours of his country, Omkarland! There are nn cities in Omkarland, and, rather curiously, there are exactly n−1n-1 bidirectional roads connecting the cities to each other. It is guaranteed that you can reach any city from any other city through the road network.

Every city has an enjoyment value ee. Each road has a capacity cc, denoting the maximum number of vehicles that can be on it, and an associated toll tt. However, the toll system in Omkarland has an interesting quirk: if a vehicle travels on multiple roads on a single journey, they pay only the highest toll of any single road on which they traveled. (In other words, they pay max⁡t\max t over all the roads on which they traveled.) If a vehicle traverses no roads, they pay 00 toll.

Omkar has decided to host qq tour groups. Each tour group consists of vv vehicles starting at city xx. (Keep in mind that a tour group with vv vehicles can travel only on roads with capacity ≥v\geq v.) Being the tour organizer, Omkar wants his groups to have as much fun as they possibly can, but also must reimburse his groups for the tolls that they have to pay. Thus, for each tour group, Omkar wants to know two things: first, what is the enjoyment value of the city yy with maximum enjoyment value that the tour group can reach from their starting city, and second, how much per vehicle will Omkar have to pay to reimburse the entire group for their trip from xx to yy? (This trip from xx to yy will always be on the shortest path from xx to yy.)

In the case that there are multiple reachable cities with the maximum enjoyment value, Omkar will let his tour group choose which one they want to go to. Therefore, to prepare for all possible scenarios, he wants to know the amount of money per vehicle that he needs to guarantee that he can reimburse the group regardless of which city they choose.

Omkar 正在为他的国家 Omkarland 举办旅游活动!Omkarland 共有 nn 座城市,且非常有趣的是,这些城市之间恰好由 n−1n-1 条双向道路连接。保证任意两座城市之间均可通过道路网络相互到达。

每座城市都有一个娱乐值 ee。每条道路都有一个容量 cc(表示该道路上最多可同时通行的车辆数)以及一个关联的过路费 tt。然而,Omkarland 的收费系统有一个有趣的特性:若一辆车在单次行程中经过多条道路,则它只需支付所经道路中最高的过路费(即,支付 max⁡t\max t,其中最大值取遍该行程所经的所有道路)。若一辆车未经过任何道路,则其过路费为 00。

Omkar 决定组织 qq 个旅游团。每个旅游团由 vv 辆车组成,均从城市 xx 出发。(请注意:一个含 vv 辆车的旅游团仅能行驶在容量 c≥vc \geq v 的道路上。)作为旅游活动组织者,Omkar 希望他的旅游团尽可能玩得开心,同时也必须为旅游团报销他们所支付的过路费。因此,对于每个旅游团,Omkar 想要知道两件事:第一,该旅游团从出发城市出发所能到达的所有城市中,娱乐值最大的城市 yy 的娱乐值是多少;第二,Omkar 为报销整个旅游团从 xx 到 yy 的行程所需向每辆车支付的金额是多少?(该 xx 到 yy 的行程将始终沿 xx 与 yy 之间的最短路径进行。)

若存在多个可达城市具有相同的最大娱乐值,Omkar 将允许旅游团自由选择前往其中任一城市。因此,为应对所有可能情况,他希望知道:为确保无论旅游团选择哪座城市,他都能完成报销,他每辆车最多需准备多少金额?

输入格式

The first line contains two integers nn and qq (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5, 1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5), representing the number of cities and the number of groups, respectively.

The next line contains nn integers e1,e2,…,ene_1, e_2, \ldots, e_n (1≤ei≤1091 \leq e_i \leq 10^9), where eie_i represents the enjoyment value for city ii.

The next n−1n-1 lines each contain four integers aa, bb, cc, and tt (1≤a,b≤n1 \leq a,b \leq n, 1≤c≤1091 \leq c \leq 10^9, 1≤t≤1091 \leq t \leq 10^9), representing an road between city aa and city bb with capacity cc and toll tt.

The next qq lines each contain two integers vv and xx (1≤v≤1091 \leq v \leq 10^9, 1≤x≤n1 \leq x \leq n), representing the number of vehicles in the tour group and the starting city, respectively.

第一行包含两个整数 nn 和 qq(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5,1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5),分别表示城市的数量和旅行团的数量。

第二行包含 nn 个整数 e1,e2,…,ene_1, e_2, \ldots, e_n(1≤ei≤1091 \leq e_i \leq 10^9),其中 eie_i 表示城市 ii 的娱乐值。

接下来的 n−1n-1 行每行包含四个整数 aa、bb、cc 和 tt(1≤a,b≤n1 \leq a,b \leq n,1≤c≤1091 \leq c \leq 10^9,1≤t≤1091 \leq t \leq 10^9),表示一条连接城市 aa 与城市 bb 的道路,其容量为 cc,通行费为 tt。

接下来的 qq 行每行包含两个整数 vv 和 xx(1≤v≤1091 \leq v \leq 10^9,1≤x≤n1 \leq x \leq n),分别表示该旅行团的车辆数和出发城市。

输出格式

Output qq lines. The ii-th line should contain two integers: the highest possible enjoyment value of a city reachable by the ii-th tour group, and the amount of money per vehicle Omkar needs to guarantee that he can reimburse the ii-th tour group.

输出 qq 行。第 ii 行应包含两个整数:第 ii 个旅游团可达城市的最高可能娱乐值,以及 Omkar 为确保能向第 ii 个旅游团报销费用而每辆车所需准备的金额。

输入输出样例

  • 输入#1

    5 3
    2 2 3 3 3
    1 2 4 7
    1 3 2 8
    2 4 8 2
    2 5 1 1
    1 3
    9 5
    6 2

    输出#1

    3 8
    3 0
    3 2
  • 输入#2

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

    输出#2

    1 0
    2 1
    3 1
    4 1
    5 1
  • 输入#3

    5 5
    1 2 2 2 2
    1 2 5 8
    1 3 6 3
    1 4 4 5
    1 5 7 1
    4 1
    5 1
    6 1
    7 1
    8 1

    输出#3

    2 8
    2 8
    2 3
    2 1
    1 0

说明/提示

A map of the first sample is shown below. For the nodes, unbolded numbers represent indices and bolded numbers represent enjoyment values. For the edges, unbolded numbers represent capacities and bolded numbers represent tolls.

For the first query, a tour group of size 11 starting at city 33 can reach cities 11, 22, 33, 44, and 55. Thus, the largest enjoyment value that they can reach is 33. If the tour group chooses to go to city 44, Omkar will have to pay 88 per vehicle, which is the maximum.

For the second query, a tour group of size 99 starting at city 55 can reach only city 55. Thus, the largest reachable enjoyment value is still 33, and Omkar will pay 00 per vehicle.

For the third query, a tour group of size 66 starting at city 22 can reach cities 22 and 44. The largest reachable enjoyment value is again 33. If the tour group chooses to go to city 44, Omkar will have to pay 22 per vehicle, which is the maximum.

A map of the second sample is shown below:

For the first query, a tour group of size 55 starting at city 11 can only reach city 11. Thus, their maximum enjoyment value is 11 and the cost Omkar will have to pay is 00 per vehicle.

For the second query, a tour group of size 44 starting at city 11 can reach cities 11 and 22. Thus, their maximum enjoyment value is 22 and Omkar will pay 11 per vehicle.

For the third query, a tour group of size 33 starting at city 11 can reach cities 11, 22, and 33. Thus, their maximum enjoyment value is 33 and Omkar will pay 11 per vehicle.

For the fourth query, a tour group of size 22 starting at city 11 can reach cities 11, 22, 33 and 44. Thus, their maximum enjoyment value is 44 and Omkar will pay 11 per vehicle.

For the fifth query, a tour group of size 11 starting at city 11 can reach cities 11, 22, 33, 44, and 55. Thus, their maximum enjoyment value is 55 and Omkar will pay 11 per vehicle.

第一个样例的地图如下所示。对于节点,非粗体数字表示索引,粗体数字表示愉悦值;对于边,非粗体数字表示容量,粗体数字表示通行费。

对于第一个查询:一个规模为 11、从城市 33 出发的旅行团可到达城市 11、22、33、44 和 55。因此,他们能到达的最大愉悦值为 33。若该旅行团选择前往城市 44,Omkar 每辆车需支付 88 的费用,这是最大值。

对于第二个查询:一个规模为 99、从城市 55 出发的旅行团仅能到达城市 55。因此,其可达的最大愉悦值仍为 33,而 Omkar 每辆车需支付的费用为 00。

对于第三个查询:一个规模为 66、从城市 22 出发的旅行团可到达城市 22 和 44。其可达的最大愉悦值仍为 33。若该旅行团选择前往城市 44,Omkar 每辆车需支付 22 的费用,这是最大值。

第二个样例的地图如下所示:

对于第一个查询:一个规模为 55、从城市 11 出发的旅行团仅能到达城市 11。因此,其最大愉悦值为 11,而 Omkar 每辆车需支付的费用为 00。

对于第二个查询:一个规模为 44、从城市 11 出发的旅行团可到达城市 11 和 22。因此,其最大愉悦值为 22,而 Omkar 每辆车需支付 11 的费用。

对于第三个查询:一个规模为 33、从城市 11 出发的旅行团可到达城市 11、22 和 33。因此,其最大愉悦值为 33,而 Omkar 每辆车需支付 11 的费用。

对于第四个查询:一个规模为 22、从城市 11 出发的旅行团可到达城市 11、22、33 和 44。因此,其最大愉悦值为 44,而 Omkar 每辆车需支付 11 的费用。

对于第五个查询:一个规模为 11、从城市 11 出发的旅行团可到达城市 11、22、33、44 和 55。因此,其最大愉悦值为 55,而 Omkar 每辆车需支付 11 的费用。

输入解题思路,AI测评打分。不知道怎么写?

首页