The campus of Nanjing University of Science and Technology can be viewed as a graph with N vertexes and M directed edges (vertexes are numbered from 0 to N-1). Each edge has the same length 1. Every day, there are K students walking to the dinning-hall (vertex N-1) from the teaching building (vertex 0) at lunch time. They all want reach the dinning-hall as soon as possible. However, each edge can only serve at most ci students at any time. Can you make arrangements for students, so that the last student can reach the dinning-hall as soon as possible? (It is assumed that the speed of the students is 1 edge per unit time)

There are several test cases, please process till EOF.
The first line of each test case contains three integer N(2<=N<=2500), M(0<=M<=5000), K(0<=K<=109). Then follows M lines, each line has three numbers ai, bi, ci(0<=ci<=20), means there is an edge from vertex ai to bi with the capacity ci.

提交代码