Test Case Tweaking#3465

Test Case Tweaking

5 seconds
32 megabytes
Easy

You are a judge of a programming contest. You are preparing a dataset for a graph problem to seek for the cost of the minimum cost path. You've generated some random cases, but they are not interesting. You want to produce a dataset whose answer is a desired value such as the number representing this year . So you will tweak (which means 'adjust') the cost of the minimum cost path to a given value by changing the costs of some edges. The number of changes should be made as few as possible.

A non-negative integer and a directed graph are given. Each edge of is associated with a cost of a non-negative integer. Given a path from one node of to another, we can define the cost of the path as the sum of the costs of edges constituting the path. Given a pair of nodes in , we can associate it with a non-negative cost which is the minimum of the costs of paths connecting them.

Given a graph and a pair of nodes in it, you are asked to adjust the costs of edges so that the minimum cost path from one node to the other will be the given target cost . You can assume that is smaller than the cost of the minimum cost path between the given nodes in the original graph.

For example, in Figure 1, the minimum cost of the path from node to node in the given graph is . In order to adjust this minimum cost to , we can change the cost of the edge from node to node to . This direct edge becomes the minimum cost path after the change.

For another example, in Figure 2, the minimum cost of the path from node to node in the given graph is . In order to adjust this minimum cost to , we can change the cost of the edge from node to node and one of the six edges in the right half of the graph. There are many possibilities of edge modification, but the minimum number of modified edges is .

Input

The input is a sequence of datasets. Each dataset is formatted as follows.

f_1 t_1 c_1 f_2 t_2 c_2 ... f_m t_m c_m

The integers , and are the number of the nodes, the number of the edges, and the target cost, respectively, each separated by a single space, where 2 \le n \le 100, 1 \le m \le 1000 and 0 \le c \le 100000.

Each node in the graph is represented by an integer through .

The following lines represent edges: the integers f_i, t_i and c_i (1 \le i \le m) are the originating node, the destination node and the associated cost of the -th edge, each separated by a single space. They satisfy 1 \le f_i, t_i \le n and 0 \le c_i \le 10000. You can assume that f_i \neq t_i and (f_i, t_i) \neq (f_j, t_j) when i \neq j.

You can assume that, for each dataset, there is at least one path from node to node , and that the cost of the minimum cost path from node to node of the given graph is greater than .

The end of the input is indicated by a line containing three zeros separated by single spaces.

Output

For each dataset, output a line containing the minimum number of edges whose cost(s) should be changed in order to make the cost of the minimum cost path from node to node equal to the target cost . Costs of edges cannot be made negative. The output should not contain any other extra characters.

Examples

Example 1

Loading
Loading