Codeforces Round 427 (Div. 2)
F
Roads in the Kingdom
Codeforces
2500
原题
← E→
翻译中…

In the Kingdom K., there are $*n*$ towns numbered with integers from $1$ to $*n*$. The towns are connected by $*n*$ bi-directional roads numbered with integers from $1$ to $*n*$. The $*i*$-th road connects the towns $*u*_{*i*}$ and $*v*_{*i*}$ and its length is $*l*_{*i*}$. There is no more than one road between two towns. Also, there are no roads that connect the towns with itself.

翻译中…

Let's call the inconvenience of the roads the maximum of the shortest distances between all pairs of towns.

翻译中…

Because of lack of money, it was decided to close down one of the roads so that after its removal it is still possible to reach any town from any other. You have to find the minimum possible inconvenience of the roads after closing down one of the roads.

翻译中…

Input

翻译中…

The first line contains the integer $*n*$ ($3 ≤ *n* ≤ 2·10^{5}$) — the number of towns and roads.

翻译中…

The next $*n*$ lines contain the roads description. The $*i*$-th from these lines contains three integers $*u*_{*i*}$, $*v*_{*i*}$, $*l*_{*i*}$ ($1 ≤ *u*_{*i*}, *v*_{*i*} ≤ *n*$, $1 ≤ *l*_{*i*} ≤ 10^{9}$) — the numbers of towns connected by the $*i*$-th road and the length of the $*i*$-th road. No road connects a town to itself, no two roads connect the same towns.

翻译中…

It's guaranteed that it's always possible to close down one of the roads so that all the towns are still reachable from each other.

翻译中…

Output

翻译中…

Print a single integer — the minimum possible inconvenience of the roads after the refusal from one of the roads.

翻译中…

样例

Input #1
3
1 2 4
2 3 5
1 3 1
Output #1
5
InputCopy OutputCopy
Input #2
5
2 3 7
3 1 9
4 1 8
3 5 4
4 5 5
Output #2
18
InputCopy OutputCopy
题目信息
题号
835F
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
动态规划
图论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。