eolymp
bolt
Try our new interface for solving problems
Problems

Tourist Huseyn

Tourist Huseyn

meme.png

Huseyn have decided to travel to another country ,but in Corona Virus season it will be difficult to have a cheap road . The bus driver has a list of the N cities in his country and calculated which paths between these cities would give more money. Each path connects two cities. The cost of the path is how many the bus driver would earn by choosing this path . Path have to be chosen so that any two paths have one city in common. Calculate the maximum cost that bus driver can have.

Input:

The first line shows the number of cities N (1N300000 ) and the number of paths M (1M500000) . Cities indexes are from 1 to N. The following M lines contain three numbers each – ai, bi (1ai, biN ) and pi (1pi1000000000 for all i ) ,where ai and bi are the two cities joined by the i-th path, and pi is the cost of the path. No two paths connect the same pair of cities.

Output:

Print a single number: the maximum possible cost.

Explanation for the first sample case:

Screenshot from 2020-11-18 14-14-42.png

Picking paths 1–2, 1–3, 1–4 would give a cost of 4 and this is the correct answer. You can select paths 1–2,1–4,2–4 as well, but cost would then be smaller – 3 .

Time limit 1 second
Memory limit 64 MiB
Input example #1
5 4
1 2 1
1 3 2
1 4 1
2 4 1
Output example #1
4
Input example #2
7 9
1 2 2
2 3 5
2 4 3
2 5 5
2 6 4
4 5 8
4 7 6
5 6 2
5 7 6
Output example #2
21
Input example #3
7 8
1 2 10
1 4 3
2 3 20
2 4 8
3 4 12
4 5 1
4 6 2
4 7 3
Output example #3
40
Source Selection for Azerbaijani Schoolers 09 November , 2020