In a certain flooded village, a secret superhuman humanitarian camp is being opened as we speak. The village consists of
Mirko has been appointed as the driver. His job is to drive around teams of volunteers in his super truck from the camp to the house where that certain team is going to work. His van is super because all teams at once can drive in it! In total, there are
All
In order for the camp manager to determine where to put up the camp, he wants to know, for each house, the minimal time it takes for Mirko to drive around all teams if that house is the headquarters. Write a program that will determine the numbers Mirko's boss wants to see!
Input Specification
The first line of input contains the integers
Each of the following
Each of the following
Output Specification
Output
Scoring
In test cases worth 50% of total points, it will hold
Sample Input 1
5 2
2 5 1
2 4 1
1 2 2
1 3 2
4
5
Sample Output 1
5
3
7
2
2
Explanation for Sample 1
If Mirko starts off at house 1, he can drop off volunteers at houses 1-2-4-2-5, respectively. If he starts off at house 2, the possible sequence is 2-5-4.
Sample Input 2
7 2
1 2 4
1 3 1
2 5 1
2 4 2
4 7 3
4 6 2
3
7
Sample Output 2
11
15
10
13
16
15
10
Comments