In conjunction with the IOI, Pattaya City will host a race: the International Olympiad in Racing (IOR) 2011. As the host, we have to find the best possible course for the race.
In the Pattaya-Chonburi metropolitan area, there are
The IOR has specific regulations that require the course to be a path whose total length is exactly
Your Task
Write a program that takes the following parameters:
– the number of cities. The cities are numbered through . – the required distance for the race course. – a two-dimensional array representing highways. For , highway connects the cities and . – a one-dimensional array representing the lengths of the highways. For , the length of highway is .
You may assume that all values in the array
Your program must output the minimum number of highways on a valid race course of length exactly -1
.
Examples
Example 1
Consider the case shown in Figure 1, where
The course can start in city
Example 2
Consider the case shown in Figure 2, where
There is no valid course. In this case, your program must output -1
.
Example 3
Consider the case shown in Figure 3, where
One possible course consists of 3 highways: from city
Input Specification
- Line
: and - Lines
to : information on the highways; i.e., line contains , , and , separated by a space, for .
Output Specification
One integer, the expected solution.
Sample Input 1
4 3
0 1 1
1 2 2
1 3 4
Sample Output 1
2
Sample Input 2
3 3
0 1 1
1 2 1
Sample Output 2
-1
Sample Input 3
11 12
0 1 3
0 2 4
2 3 5
3 4 4
4 5 6
0 6 3
6 7 2
6 8 5
8 9 6
8 10 7
Sample Output 3
2
Subtasks
Subtask 1 (9 points)
- The network of highways forms the simplest possible line: For
, highway connects cities and .
Comments