#abc237e. E - Skiing
E - Skiing
Score : points
问题描述
在 AtCoder 滑雪场有 个开放区域,分别称为 Space 、Space 、、Space 。其中,Space 的海拔高度为 。存在 条双向连接两个空间的滑雪道。第 条滑雪道()连接了 Space 和 Space 。通过一些滑雪道,可以在任意两个空间之间穿梭。
高桥只能通过滑雪道在各空间之间移动。每次他经过一条滑雪道时,他的幸福感会发生变化。具体来说,当他通过直接相连的滑雪道从 Space 移动到 Space 时,其幸福感的变化如下:
- 如果 Space 的海拔高于 Space ,幸福感会增加两者之差:。
- 如果 Space 的海拔低于 Space ,幸福感会减少两者之差的两倍:。
- 如果 Space 的海拔等于 Space ,幸福感不变。
幸福感可能为负值。
最初,高桥位于 Space ,且其幸福感为 。请找出经过任意数量滑雪道(包括零条)后,以任意一个空间为终点时,他所能达到的最大幸福感。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
AtCoder Ski Area has open spaces called Space , Space , , Space . The altitude of Space is . There are slopes that connect two spaces bidirectionally. The -th slope connects Space and Space . It is possible to travel between any two spaces using some slopes.
Takahashi can only travel between spaces by using slopes. Each time he goes through a slope, his happiness changes. Specifically, when he goes from Space to Space by using the slope that directly connects them, his happiness changes as follows.
- If the altitude of Space is strictly higher than that of Space , the happiness increases by their difference: .
- If the altitude of Space is strictly lower than that of Space , the happiness decreases by their difference multiplied by : .
- If the altitude of Space is equal to that of Space , the happiness does not change.
The happiness may be a negative value.
Initially, Takahashi is in Space , and his happiness is . Find his maximum possible happiness after going through any number of slopes (possibly zero), ending in any space.
Constraints
- $N-1 \leq M \leq \min( 2\times 10^5,\frac{N(N-1)}{2})$
- if .
- All values in input are integers.
- It is possible to travel between any two spaces using some slopes.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4 4
10 8 12 5
1 2
1 3
2 3
3 4
Sample Output 1
3
If Takahashi takes the route Space Space Space , his happiness changes as follows.
- When going from Space (altitude ) to Space (altitude ), it decreases by and becomes .
- When going from Space (altitude ) to Space (altitude ), it increases by and becomes .
If he ends the travel here, the final happiness will be , which is the maximum possible value.
Sample Input 2
2 1
0 10
1 2
Sample Output 2
0
His happiness is maximized by not moving at all.
update @ 2024/3/10 10:16:00