QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 128 MB Points totaux : 10

#10645. Winter [B]

Statistiques

Winter has come to Bajtocja. Bajtazar, a snowplow driver, was not caught off guard and set out to clear the streets of Bajtogród.

The road network in Bajtogród consists of $n$ intersections connected by $n-1$ bidirectional streets. From every intersection, it is possible to reach any other intersection by exactly one path consisting of one or more streets without turning back.

Snow falls continuously, so the streets must be constantly cleared again. For each street, Bajtazar knows the minimum number of times it must be cleared during the day (it does not matter to him at what moments of the day he does this). Bajtazar can start clearing at any intersection. He would like to plan his work so that the total number of streets traversed is as small as possible. Naturally, traversing the same street multiple times counts multiple times.

Input

The first line of input contains a single integer $n$ ($2 \le n \le 500\,000$) representing the number of intersections in Bajtogród. The next $n-1$ lines describe the individual streets. Each of these lines contains three integers $a_{i}$, $b_{i}$, $d_{i}$ ($1 \le a_i, b_i \le n$, $a_i \ne b_i$, $1 \le d_i \le 100\,000$) indicating that intersections $a_{i}$ and $b_{i}$ are connected by a bidirectional street that must be cleared at least $d_{i}$ times during the day.

Output

Output a single line containing the minimum number of streets Bajtazar must traverse to satisfy the given requirements.

Examples

Input 1

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

Output 1

8

Note

Bajtazar's optimal route traverses eight streets: 1 → 2 → 3 → 5 → 4 → 5 → 6 → 5 → 3.

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.