eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Test Case Tweaking

Test Case Tweaking

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 \textbf{2010}. 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 \textbf{c} and a directed graph \textbf{G} are given. Each edge of \textbf{G} is associated with a cost of a non-negative integer. Given a path from one node of \textbf{G} 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 \textbf{G}, 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 \textbf{c}. You can assume that \textbf{c} 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 \textbf{1} to node \textbf{3} in the given graph is \textbf{6}. In order to adjust this minimum cost to \textbf{2}, we can change the cost of the edge from node \textbf{1} to node \textbf{3} to \textbf{2}. 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 \textbf{1} to node \textbf{12} in the given graph is \textbf{4022}. In order to adjust this minimum cost to \textbf{2010}, we can change the cost of the edge from node \textbf{6} to node \textbf{12} 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 \textbf{2}. \InputFile The input is a sequence of datasets. Each dataset is formatted as follows. \textbf{n m cf_1 t_1 c_1f_2 t_2 c_2...} \textbf{f_m t_m c_m} The integers \textbf{n}, \textbf{m} and \textbf{c} are the number of the nodes, the number of the edges, and the target cost, respectively, each separated by a single space, where \textbf{2} ≤ \textbf{n} ≤ \textbf{100}, \textbf{1} ≤ \textbf{m} ≤ \textbf{1000} and \textbf{0} ≤ \textbf{c} ≤ \textbf{100000}. Each node in the graph is represented by an integer \textbf{1} through \textbf{n}. The following \textbf{m} lines represent edges: the integers \textbf{f_i}, \textbf{t_i} and \textbf{c_i} (\textbf{1} ≤ \textbf{i} ≤ \textbf{m}) are the originating node, the destination node and the associated cost of the \textbf{i}^\{-th\} edge, each separated by a single space. They satisfy \textbf{1} ≤ \textbf{f_i}, \textbf{t_i} ≤ \textbf{n} and \textbf{0} ≤ \textbf{c_i} ≤ \textbf{10000}. You can assume that \textbf{f_i = t_i} and (\textbf{f_i}, \textbf{t_i}) = (\textbf{f_j}, \textbf{t_j}) when \textbf{i = j}. You can assume that, for each dataset, there is at least one path from node \textbf{1} to node \textbf{n}, and that the cost of the minimum cost path from node \textbf{1} to node \textbf{n} of the given graph is greater than \textbf{c}. The end of the input is indicated by a line containing three zeros separated by single spaces. \OutputFile 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 \textbf{1} to node \textbf{n} equal to the target cost \textbf{c}. Costs of edges cannot be made negative. The output should not contain any other extra characters.
Ліміт часу 5 секунд
Ліміт використання пам'яті 32 MiB
Вхідні дані #1
3 3 3
1 2 3
2 3 3
1 3 8
12 12 2010
1 2 0
2 3 3000
3 4 0
4 5 3000
5 6 3000
6 12 2010
2 7 100
7 8 200
8 9 300
9 10 400
10 11 500
11 6 512
10 18 1
1 2 9
1 3 2
1 4 6
2 5 0
2 6 10
2 7 2
3 5 10
3 6 3
3 7 10
4 7 6
5 8 10
6 8 2
6 9 11
7 9 3
8 9 9
8 10 8
9 10 1
8 2 1
0 0 0
Вихідні дані #1
1
2
3
Джерело ACM ICPC Regionals 2010, Asia, Tokyo