PivotOJ

Profitable Trip

시간 제한: 7000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2022-2023BOJ 27586

문제

You are planning a road trip. You have carefully mapped out all potential waypoints that you may stop at. From each waypoint, there are roads that allow you to drive to other waypoints, but roads can only be used in one direction. In order to alleviate traffic jams, the road planners have decided to require tolls on the more popular roads. The less popular roads may even pay you to drive on them.

As a result, it may be possible to make a profit from the road trip. But there is a catch---your wallet can only hold a maximum of ww dollars more than what you have started with. You are allowed to get paid even when your wallet is full, but you will not be able to keep more than ww dollars over what you started with. You may assume that whenever you need to pay a toll, you will have money to pay.

What is the maximum profit you can make on your trip?

입력

The first line of input contains three integers nn, mm, and ww (1n,m20001 \leq n, m \leq 2\,000, 1w1001 \leq w \leq 100), where nn is the number of waypoints, mm is the number of roads, and ww is the additional capacity of your wallet. The waypoints are numbered 11 through nn. The first waypoint (11) is the start of your road trip, and the last waypoint (nn) is the destination.

Each of the next mm lines contains three integers uu, vv, and tt (1u,vn1 \leq u, v \leq n, 100t100-100 \leq t \leq 100), indicating that there is a road from waypoint uu to waypoint vv, with a gain of tt dollars. If t>0t > 0, then you are paid tt dollars to use the road. If t<0t < 0, you must pay a toll of t|t| dollars to use the road, resulting in a change of tt to your profit. It is guaranteed that uvu \neq v, and there is at most one road from uu to vv (but there can also be a road from vv to uu).

You may assume that it is possible to reach waypoint nn from waypoint 1.

출력

Output a single integer, which is the maximum profit you can make during the road trip. If there is a loss, output the loss as a negative number.

예제

예제 1

입력
4 4 9
1 2 5
1 3 -2
2 4 1
3 4 10
출력
8

예제 2

입력
4 4 7
1 2 5
1 3 -2
2 4 1
3 4 10
출력
7

예제 3

입력
3 3 5
1 3 -10
3 2 2
2 3 -1
출력
4
코드를 제출하려면 로그인하세요.