#P4408. [NOI2003] 逃学的小孩 / 数据生成器

    ID: 3326 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2003NOI 系列枚举,暴力树的直径

[NOI2003] 逃学的小孩 / 数据生成器

Description

The phone at Chris's home rang, and Chris's teacher spoke anxiously: "Hello, is this Chris's parent? Your child skipped class again. Does he not want to take the exam?" Hearing about an exam, Chris's parents became very worried. They decided to find Chris in the shortest possible time. They told the teacher: "Based on past experience, Chris must be hiding at his friend Shermie or Yashiro's home, secretly playing The King of Fighters. Now, we'll set out from home to find Chris. As soon as we find him, we'll call you." With a bang, they hung up.

Chris's city consists of NN residential points and several undirected streets connecting them. It takes TxT_{x} minutes to traverse street xx. It is guaranteed that between any two residential points there is exactly one path. Chris's home is at point CC, and Shermie and Yashiro live at points AA and BB, respectively. Both the teacher and Chris's parents have the city map, but only Chris's parents know the exact locations of AA, BB, and CC; the teacher does not.

To find Chris as quickly as possible, Chris's parents will follow these two rules:

  1. If the distance from AA to CC is shorter than the distance from BB to CC, then Chris's parents will first go to Shermie's home to look for Chris. If he is not there, they will then go to Yashiro's home; and vice versa.
  2. Chris's parents always walk along the unique path between two points.

Clearly, the teacher knows that Chris's parents will follow the above two rules during their search. However, since he does not know the exact locations of AA, BB, and CC, he would like you to tell him: in the worst case, how long will it take Chris's parents to find Chris?

Input Format

The first line of the input contains two integers NN and MM, representing the total number of residential points and the total number of streets, respectively.

Each of the next MM lines describes one street. Line i+1i+1 contains integers UiU_{i}, ViV_{i}, and TiT_{i}, indicating that street ii connects residential points UiU_{i} and ViV_{i}, and it takes TiT_{i} minutes to traverse street ii. No street information is given more than once.

Output Format

Output a single integer TT, the number of minutes Chris's parents will need in the worst case to find Chris.

4 3
1 2 1
2 3 1
3 4 1
4

Hint

For 100%100\% of the testdata, 3N2×1053 \le N \le 2\times 10^5, 1Ui,ViN1 \le U_{i},V_{i} \le N, 0Ti1090 \le T_{i} \le 10^{9}.

Translated by ChatGPT 5