import sys

sys.setrecursionlimit(10 ** 9)



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, M, P = lr()

graph = [lr() for _ in range(M)]



def bellmanford(s, g):

    INF = 10**19

    dist = [INF] * (N+1)

    dist[s] = 0

    for i in range(2 * N):

        for a, b, c in graph:

            if dist[a] != INF and dist[b] > dist[a] - c + P:

                dist[b] = dist[a] - c + P

                if i >= N:

                    dist[b] = -float("inf")

 

    if dist[g] == -float("inf"):

        return -1

    else:

        return max(-dist[g], 0)



answer = bellmanford(1, N)

print(answer)

# 

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, M, P = lr()

# 終了時、T*P枚支払う

graph = []

for _ in range(M):

    a, b, c = lr()

    graph.append((a, b, c))



def bellmanford(N, start):

    INF = 10 ** 12

    dist = [-INF] * (N+1) # 1-indexed

    dist[start] = 0

    for i in range(N+N+5):

        for (pre, ne, weight) in graph:

            if dist[pre] != -INF and dist[pre] + weight - P > dist[ne]:

                dist[ne] = dist[pre] + weight - P

                # n回繰り返してもスコアが更新された場合

                if i > N-1:

                    dist[ne] = INF

    if dist[N] == INF:

        return -1

    else:

        return max(0, dist[N])



answer = bellmanford(N, 1)

print(answer)

import sys

sys.setrecursionlimit(10**9)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M, P = lr()
graph = [lr() for _ in range(M)]


def bellmanford(s, g):
    INF = 10**19
    dist = [INF] * (N + 1)
    dist[s] = 0
    for i in range(2 * N):
        for a, b, c in graph:
            if dist[a] != INF and dist[b] > dist[a] - c + P:
                dist[b] = dist[a] - c + P
                if i >= N:
                    dist[b] = -float("inf")
    if dist[g] == -float("inf"):
        return -1
    else:
        return max(-dist[g], 0)


answer = bellmanford(1, N)
print(answer)
#

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M, P = lr()
# 終了時、T*P枚支払う
graph = []
for _ in range(M):
    a, b, c = lr()
    graph.append((a, b, c))


def bellmanford(N, start):
    INF = 10**12
    dist = [-INF] * (N + 1)  # 1-indexed
    dist[start] = 0
    for i in range(N + N + 5):
        for (pre, ne, weight) in graph:
            if dist[pre] != -INF and dist[pre] + weight - P > dist[ne]:
                dist[ne] = dist[pre] + weight - P
                # n回繰り返してもスコアが更新された場合
                if i > N - 1:
                    dist[ne] = INF
    if dist[N] == INF:
        return -1
    else:
        return max(0, dist[N])


answer = bellmanford(N, 1)
print(answer)

-sys.setrecursionlimit(10**9) -graph = [lr() for _ in range(M)] +# 終了時、T*P枚支払う +graph = [] +for _ in range(M): +    a, b, c = lr() +    graph.append((a, b, c)) -def bellmanford(s, g): -    INF = 10**19 -    dist = [INF] * (N + 1) -    dist[s] = 0 -    for i in range(2 * N): -        for a, b, c in graph: -            if dist[a] != INF and dist[b] > dist[a] - c + P: -                dist[b] = dist[a] - c + P -                if i >= N: -                    dist[b] = -float("inf") -    if dist[g] == -float("inf"): +def bellmanford(N, start): +    INF = 10**12 +    dist = [-INF] * (N + 1)  # 1-indexed +    dist[start] = 0 +    for i in range(N + N + 5): +        for (pre, ne, weight) in graph: +            if dist[pre] != -INF and dist[pre] + weight - P > dist[ne]: +                dist[ne] = dist[pre] + weight - P +                # n回繰り返してもスコアが更新された場合 +                if i > N - 1: +                    dist[ne] = INF +    if dist[N] == INF: -        return max(-dist[g], 0) +        return max(0, dist[N]) -answer = bellmanford(1, N) +answer = bellmanford(N, 1) -#