Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 32768/32768 K (Java/Others)

There are N cities, and M directed roads connecting them. Now you want to transport K units of goods from city 1 to city N. There are many robbers on the road, so you must be very careful. The more goods you carry, the more dangerous it is. To be more specific, for each road i, there is a coefficient a_{i}. If you want to carry x units of goods along this road, you should pay a_{i} * x^{2} dollars to hire guards to protect your goods. And what’s worse, for each road i, there is an upper bound C_{i}, which means that you cannot transport more than C_{i} units of goods along this road. Please note you can only carry integral unit of goods along each road.

You should find out the minimum cost to transport all the goods safely.

You should find out the minimum cost to transport all the goods safely.

There are several test cases. The first line of each case contains three integers, N, M and K. (1 <= N <= 100, 1 <= M <= 5000, 0 <= K <= 100). Then M lines followed, each contains four integers (u_{i}, v_{i}, a_{i}, C_{i}), indicating there is a directed road from city u_{i} to v_{i}, whose coefficient is a_{i} and upper bound is C_{i}. (1 <= u_{i}, v_{i} <= N, 0 < a_{i} <= 100, C_{i} <= 5)

提交代码