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.
输入格式
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.
输出格式
Print a single integer — the minimum possible inconvenience of the roads after the refusal from one of the roads.
inlinevoidInput(){ read(n); int u, v, w; for(int i = 1; i <= n; i++) { read(u, v, w); G.AddEdge(u, v, w); G.AddEdge(v, u, w); } }
int vis[MaxV]; int Cir[MaxV], tot; ll dis[MaxV];
intGetCircle(int u, int fa = -1){ if(vis[u]) return u; else vis[u] = -1; for(int i = G.head(u); i; i = G.nt(i)) { int v = G.to(i), now = GetCircle(v, u); if(v != fa && now) { Cir[++tot] = u, dis[tot] = G.wt(i); vis[u] = 1; return now == u ? 0 : now; } } return0; }
ll ans1, ans2, dp[MaxV];
voidDfs(int u, int fa = -1){ for(int i = G.head(u); i; i = G.nt(i)) { int v = G.to(i); if(vis[v] != 1 && v != fa) { Dfs(v, u); ans1 = max(ans1, dp[u] + dp[v] + G.wt(i)); dp[u] = max(dp[u], dp[v] + G.wt(i)); } } }