#P4408. [NOI2003] 逃学的小孩 / 数据生成器
[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 residential points and several undirected streets connecting them. It takes minutes to traverse street . It is guaranteed that between any two residential points there is exactly one path. Chris's home is at point , and Shermie and Yashiro live at points and , respectively. Both the teacher and Chris's parents have the city map, but only Chris's parents know the exact locations of , , and ; the teacher does not.
To find Chris as quickly as possible, Chris's parents will follow these two rules:
- If the distance from to is shorter than the distance from to , 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.
- 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 , , and , 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 and , representing the total number of residential points and the total number of streets, respectively.
Each of the next lines describes one street. Line contains integers , , and , indicating that street connects residential points and , and it takes minutes to traverse street . No street information is given more than once.
Output Format
Output a single integer , 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 of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号