問題一覧 > 通常問題

No.1833 Subway Planning

レベル : / AI推定難易度 : 2000 / 実行時間制限 : 1ケース 4.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 44
作問者 : riano / テスター : ygussany milkcoffee
お気に入りにしたユーザー ProblemId : 7447 / 自分の提出
問題文最終更新日: 2022-01-10 19:13:29
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 330 (順位表) の他の問題:

Problem Statement

yukicoder City has $N$ intersections numbered from $1$ to $N$, connected by $N-1$ bidirectional roads. Here, it is guaranteed that any $2$ intersections can be reached from each other by passing through some number of roads (that is, the intersections as vertices and the roads as edges form a tree).

Among these, the $i$-th road connects intersections $A_i$ and $B_i$ and has a congestion level of $C_i$. The maximum of the congestion levels of the roads in the city is defined as the "overall traffic congestion level of the city" and is denoted by $D$. You want to choose $2$ intersections and build exactly $1$ subway line connecting those $2$ points, so as to make the value of $D$ as small as possible. Given that building the subway affects the congestion level of each road as described below, what is the minimum achievable value of $D$?

[Change in Congestion Levels]
Suppose the subway connects $2$ intersections $p,q$. Then, for the roads on the shortest path between $p,q$, let $m$ be the minimum congestion level among those roads; the congestion levels of these roads all decrease by $m$ simultaneously. The congestion levels of roads not on the shortest path between $p,q$ do not change.

Input

$N$
$A_1$ $B_1$ $C_1$
$A_2$ $B_2$ $C_2$
...
$A_{N-1}$ $B_{N-1}$ $C_{N-1}$

  • $2\leq N\leq 2\times 10^5$
  • $1\leq A_i,B_i\leq N$ $(1\leq i\leq N-1)$
  • The given graph is a tree
  • $1\leq C_i\leq 10^9$ $(1\leq i\leq N-1)$
  • All inputs are integers

Output

Output the minimum achievable value of the "overall traffic congestion level of the city" $D$ as an integer. Print a newline at the end.

Sample

Sample 1
Input
4
1 2 1
2 3 2
3 4 3
Output
1

The given information is shown in the figure below. Building a subway connecting intersections $2$ and $4$ results in the state labeled [After Change] in the figure, achieving an overall traffic congestion level of $D=1$. It cannot be made smaller than this, so this is the answer.

Sample 2
Input
4
2 1 100
3 1 90
4 1 80
Output
80

Note that the subway is built by choosing $2$ intersections; in particular, branching is not allowed.

Sample 3
Input
9
1 2 15
3 1 10
2 4 8
5 6 7
5 2 9
3 8 7
7 3 2
3 9 5
Output
8

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。