CF1016F.Road Projects

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn cities in the country of Berland. Some of them are connected by bidirectional roads in such a way that there exists exactly one path, which visits each road no more than once, between every pair of cities. Each road has its own length. Cities are numbered from 11 to nn.

The travelling time between some cities vv and uu is the total length of the roads on the shortest path from vv to uu.

The two most important cities in Berland are cities 11 and nn.

The Berland Ministry of Transport decided to build a single new road to decrease the traffic between the most important cities. However, lots of people are used to the current travelling time between the most important cities, so the new road shouldn't change it too much.

The new road can only be built between such cities vv and uu that v≠uv \neq u and vv and uu aren't already connected by some road.

They came up with mm possible projects. Each project is just the length xx of the new road.

Polycarp works as a head analyst at the Berland Ministry of Transport and it's his job to deal with all those mm projects. For the ii-th project he is required to choose some cities vv and uu to build the new road of length xix_i between such that the travelling time between the most important cities is maximal possible.

Unfortunately, Polycarp is not a programmer and no analyst in the world is capable to process all projects using only pen and paper.

Thus, he asks you to help him to calculate the maximal possible travelling time between the most important cities for each project. Note that the choice of vv and uu can differ for different projects.

伯兰德国有 nn 座城市。其中一些城市通过双向道路相连,使得任意两座城市之间都恰好存在一条路径(每条道路至多经过一次)。每条道路都有其自身的长度。城市编号为 11 到 nn。

城市 vv 与 uu 之间的通行时间定义为从 vv 到 uu 的最短路径上所有道路长度的总和。

伯兰德国两个最重要的城市是城市 11 和城市 nn。

伯兰德交通部决定修建一条新道路,以缓解两个最重要城市之间的交通压力。然而,许多人已习惯当前两个最重要城市之间的通行时间,因此新道路不应使该通行时间发生过大变化。

新道路只能修建在满足以下条件的两座城市 vv 和 uu 之间:v≠uv \neq u,且 vv 与 uu 当前尚未由任何道路直接相连。

他们共提出了 mm 个备选方案。每个方案仅指定新道路的长度 xx。

波利卡普在伯兰德交通部担任首席分析师,处理全部 mm 个方案正是他的职责。对于第 ii 个方案,他需要选定两座城市 vv 和 uu,并在其间修建一条长度为 xix_i 的新道路,使得两个最重要城市之间的通行时间尽可能大。

不幸的是,波利卡普并非程序员,且世界上没有任何一位分析师能单靠纸笔完成全部方案的计算。

因此,他请求你帮助他计算出:对每个方案,两个最重要城市之间所能达到的最大可能通行时间。注意:不同方案所选择的 vv 和 uu 可以不同。

输入格式

The first line contains two integers nn and mm (3≤n≤3⋅1053 \le n \le 3 \cdot 10^5, 1≤m≤3⋅1051 \le m \le 3 \cdot 10^5) — the number of cities and the number of projects, respectively.

Each of the next n−1n - 1 lines contains three integers viv_i, uiu_i and wiw_i (1≤vi,ui≤n1 \le v_i, u_i \le n, 1≤wi≤1091 \le w_i \le 10^9) — the description of the ii-th road. It is guaranteed that there exists exactly one path, which visits each road no more than once, between every pair of cities.

Each of the next mm lines contains a single integer xjx_j (1≤xj≤1091 \le x_j \le 10^9) — the length of the road for the jj-th project.

第一行包含两个整数 nn 和 mm(3≤n≤3⋅1053 \le n \le 3 \cdot 10^5,1≤m≤3⋅1051 \le m \le 3 \cdot 10^5)—— 分别表示城市的数量和项目的数量。

接下来的 n−1n - 1 行中,每行包含三个整数 viv_i、uiu_i 和 wiw_i(1≤vi,ui≤n1 \le v_i, u_i \le n,1≤wi≤1091 \le w_i \le 10^9)—— 描述第 ii 条道路。保证任意两座城市之间均存在唯一一条路径,且该路径上每条道路至多经过一次。

接下来的 mm 行中,每行包含一个整数 xjx_j(1≤xj≤1091 \le x_j \le 10^9)—— 表示第 jj 个项目的道路长度。

输出格式

Print mm lines, the jj-th line should contain a single integer — the maximal possible travelling time between the most important cities for the jj-th project.

输出 mm 行,其中第 jj 行应包含一个整数——第 jj 个项目的最重要城市之间可能的最大旅行时间。

输入输出样例

  • 输入#1

    7 2
    1 2 18
    2 3 22
    3 4 24
    4 7 24
    2 6 4
    3 5 12
    1
    100

    输出#1

    83
    88

说明/提示

The road network from the first example:

You can build the road with length 11 between cities 55 and 66 to get 8383 as the travelling time between 11 and 77 (1→2→6→5→3→4→71 \rightarrow 2 \rightarrow 6 \rightarrow 5 \rightarrow 3 \rightarrow 4 \rightarrow 7 == 18+4+1+12+24+24=8318 + 4 + 1 + 12 + 24 + 24 = 83). Other possible pairs of cities will give answers less or equal to 8383.

第一个样例中的道路网络:

你可以在城市 55 和 66 之间修建一条长度为 11 的道路,使得城市 11 与城市 77 之间的通行时间为 8383(路径为 1→2→6→5→3→4→71 \rightarrow 2 \rightarrow 6 \rightarrow 5 \rightarrow 3 \rightarrow 4 \rightarrow 7,对应时间为 18+4+1+12+24+24=8318 + 4 + 1 + 12 + 24 + 24 = 83)。其余任意一对城市之间修建道路所得的通行时间均不超过 8383。

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

首页