You have recently started playing a brand new computer game called "Mr. President". The game is about ruling a country, building infrastructures and developing it.
Your country consists of N cities and M bidirectional roads connecting them. Each road has assigned a cost of its maintenance. The greatest achievement in the game is called "Great administrator" and it is given to a player who manage to have all cities in the country connected by roads in such a way that it is possible to travel between any two cities and that the sum of maintenance costs of these roads is not greater than K.
This is very hard to accomplish, but you are very close to do it. More precisely, you have just discovered a new method of transforming standard roads into super roads, with cost of maintenance just 1, due to their extreme durability. The bad news is that it is very expensive to transform a standard road into a super road, but you are so excited that you are going to do it anyway.
In addition, because you have a lot of other expenses, you also want to first demolish as many roads as possible in order to save some money on their maintenance first and then start working on getting the achievement. You can demolish any road in the country and that operation does not cost you anything. Because you want to spend the absolutely minimum money in order to get the achievement, you are interested in the smallest number of transformations of standard roads into super roads in such a way that you can do that.
Input Format
The first line of input contains 3 integers N, M and K denoting the number of cities in the country, the number of roads in it and the desired sum of costs of maintenance respectively. Followed by M lines describing these roads. In each of them there are 3 integers A, B and C, where A and B denotes the endpoints of the road while C denotes the cost of its maintenance.
Example Input
3 3 25
1 2 10
2 3 20
3 1 30
Output Format
In a single line, output the minimum number of roads which need to be transformed in order to get the achievement. If you cannot do it no matter what, output -1.
Example Output
1
Explanation
You can transform to super a road either the road between cities 1 and 2 or the road between cities 2 and 3 in order to produce the desired road network of costs respectively 21 and 11. Doing that will cost you one transformation and it is optimal in this case.
Another Example:
Example Input
3 3 15
1 2 10
2 3 20
3 1 30
Example Output
1
Explanation
You can transform to super a road either the road between cities 1 and 2 and the road between cities 2 and 3 in order to produce the desired road network of costs 2. Doing that will cost you two transformation and it is not optimal in this case. Hence, transforming the road between cities 2 and 3 will produce the desired road network of costs 11 and doing that will cost you one transformation and it is optimal in this case
Answers
Answered by
2
Answer:
refer to the attachment drop some thx plz
Attachments:
Similar questions