QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 512 MB Puntuación total: 100 Hackeable ✓

#4216. 面白いセールスマン

Estadísticas

重み付きの木が与えられる。各辺の重みは非負整数である。 $d(u, v)$ を、頂点 $u$ と頂点 $v$ を結ぶ唯一の単純パス上の辺の重みの最大値とする。 頂点のすべての順列 $p_1, p_2, \dots, p_n$ の中で、$\sum_{i=2}^{n} 2^{d(p_{i-1}, p_i)}$ の最大値を求めよ。

入力

1行目に整数 $n$ ($2 \le n \le 100\,000$) が与えられる。これは木の頂点数である。 続く $n-1$ 行の各行には、3つの整数 $u, v, w$ ($1 \le u, v \le n, 0 \le w \le 30$) が与えられる。これは、端点が $u, v$ で重みが $w$ である木上の辺を表す。

出力

$\sum_{i=2}^{n} 2^{d(p_{i-1}, p_i)}$ の最大値を1つの整数として出力せよ。

入出力例

入力 1

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

出力 1

6

注記

最初の例において、最適な順列の1つは $\{4, 5, 3, 2, 1\}$ である。

入力 2

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

出力 2

42

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.