#P14633. [2018 KAIST RUN Fall] Utilitarianism
[2018 KAIST RUN Fall] Utilitarianism
题目描述
In RUN-land, there are cities numbered to . Some pairs of cities are connected by a bidirectional road. It happens that there are roads in total and that for any two cities, there is a unique path from one to the other. Also, each road is assigned an integer called the .
Today, to honor the co-founders of RUN-land, Alex, the king of RUN-land, has decided to choose different roads and give one road to each of the co-founders. To prevent unnecessary conflicts, there should be no city that is connected to more than one chosen roads.
In this process, Alex, the king of RUN-land, does not care about who gets what road. Instead, Alex, the king of RUN-land, is only interested in the sum of the values of the chosen roads. Your task is to choose the roads to maximize this sum.
输入格式
The first line contains two integers and (,), which are the number of cities in RUN-land, and the number of roads to choose. Each of the next lines contains three integers (, ), which means that the city and the city are directly connected with a bidirectional road with value .
输出格式
If there is no way to choose roads to satisfy the conditions, print . Otherwise, print one integer, the maximum sum of the values of the chosen roads.
5 1
1 2 2
2 3 3
2 4 10
4 5 6
10
5 2
1 2 2
2 3 3
2 4 10
4 5 6
9
5 3
1 2 2
2 3 3
2 4 10
4 5 6
Impossible