#t516. 信使
信使
Messengers
Special for beginners, ^_^
Problem Description
During wartime there are outposts on the front line. Each outpost may be in communication with several other outposts. Messengers carry messages between outposts, which of course takes some time (measured in days). The headquarters is stationed at the first outpost. When headquarters issues an order, it sends several messengers to the outposts directly connected to it. Once an outpost receives a message, the messengers stationed there forward it to other outposts in the same way. The delivery succeeds only when all outposts have received the order. Because of careful preparation, each outpost has enough messengers (if an outpost communicates with other outposts, at least messengers are stationed there).
The commander-in-chief asks you to write a program that computes the minimum time needed to complete the whole delivery process.
Input Format
The first line contains two integers and separated by one space: there are outposts and communication lines. .
Lines through : each line has three integers separated by one space, meaning there is a communication line between outposts and , and that line takes days.
Output Format
One integer: the minimum time for the whole delivery process. If not all outposts can receive the message, output .
Sample Input 1
4 4
1 2 4
2 3 7
2 4 1
3 4 6
Sample Output 1
11
Constraints
1s, 1024KiB for each test case.