N, M, P = list(map(int, input().split()))



ABC = []

for _ in range(M):

    a, b, c = list(map(int, input().split()))

    ABC.append((a - 1, b - 1, P - c))



inf = float("inf")

d = [inf] * N

d[0] = 0



# Bellman-Ford

for i in range(N):

    for a, b, c in ABC:

        if d[b] <= d[a] + c:

            continue

        d[b] = d[a] + c

ans = d[N - 1]

for i in range(N):

    for a, b, c in ABC:

        if d[b] <= d[a] + c:

            continue

        d[b] = d[a] + c

if ans != d[N - 1]:

    print((-1))

else:

    print((max(0, -d[N - 1])))

N, M, P = list(map(int, input().split()))



ABC = []

for _ in range(M):

    a, b, c = list(map(int, input().split()))

    ABC.append((a - 1, b - 1, P - c))



inf = float("inf")

d = [inf] * N

d[0] = 0



# Bellman-Ford

for i in range(N):

    for a, b, c in ABC:

        if d[b] <= d[a] + c:

            continue

        d[b] = d[a] + c

ans = d[N - 1]

for i in range(N):

    for a, b, c in ABC:

        if d[b] <= d[a] + c:

            continue

        d[b] = -inf

if ans != d[N - 1]:

    print((-1))

else:

    print((max(0, -d[N - 1])))

N, M, P = list(map(int, input().split()))
ABC = []
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    ABC.append((a - 1, b - 1, P - c))
inf = float("inf")
d = [inf] * N
d[0] = 0
# Bellman-Ford
for i in range(N):
    for a, b, c in ABC:
        if d[b] <= d[a] + c:
            continue
        d[b] = d[a] + c
ans = d[N - 1]
for i in range(N):
    for a, b, c in ABC:
        if d[b] <= d[a] + c:
            continue
        d[b] = d[a] + c
if ans != d[N - 1]:
    print((-1))
else:
    print((max(0, -d[N - 1])))

N, M, P = list(map(int, input().split()))
ABC = []
for _ in range(M):
    a, b, c = list(map(int, input().split()))
    ABC.append((a - 1, b - 1, P - c))
inf = float("inf")
d = [inf] * N
d[0] = 0
# Bellman-Ford
for i in range(N):
    for a, b, c in ABC:
        if d[b] <= d[a] + c:
            continue
        d[b] = d[a] + c
ans = d[N - 1]
for i in range(N):
    for a, b, c in ABC:
        if d[b] <= d[a] + c:
            continue
        d[b] = -inf
if ans != d[N - 1]:
    print((-1))
else:
    print((max(0, -d[N - 1])))

-        d[b] = d[a] + c +        d[b] = -inf