#P14633. [2018 KAIST RUN Fall] Utilitarianism

    ID: 14500 Type: RemoteJudge 5000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 8 Uploaded By: Tags>2018凸完全单调性(wqs 二分)高校校赛

[2018 KAIST RUN Fall] Utilitarianism

题目描述

In RUN-land, there are nn cities numbered 11 to nn. Some pairs of cities are connected by a bidirectional road. It happens that there are n1n-1 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 value\textit{value}.

Today, to honor the kk co-founders of RUN-land, Alex, the king of RUN-land, has decided to choose kk different roads and give one road to each of the kk 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 kk chosen roads. Your task is to choose the roads to maximize this sum.

输入格式

The first line contains two integers nn and kk (2n2500002\leq n\leq250000,1kn11\leq k\leq n-1), which are the number of cities in RUN-land, and the number of roads to choose. Each of the next n1n-1 lines contains three integers u,v,cu,v,c (1u,vn1\leq u,v\leq n, 106c106-10^6\leq c\leq 10^6), which means that the city uu and the city vv are directly connected with a bidirectional road with value cc.

输出格式

If there is no way to choose kk roads to satisfy the conditions, print Impossible\tt{Impossible}. Otherwise, print one integer, the maximum sum of the values of the kk 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