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])))

from collections import deque



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))



# preprocess

to = [[] for _ in range(N)]

fr = [[] for _ in range(N)]

for a, b, c in ABC:

    to[a].append(b)

    fr[b].append(a)



visitable_s = [False] * N

q = deque()

q.append(0)

visitable_s[0] = True

while len(q):

    a = q.pop()

    for b in to[a]:

        if not visitable_s[b]:

            visitable_s[b] = True

            q.append(b)



visitable_g = [False] * N

q = deque()

q.append(N - 1)

visitable_g[N - 1] = True

while len(q):

    a = q.pop()

    for b in fr[a]:

        if not visitable_g[b]:

            visitable_g[b] = True

            q.append(b)



visitable = [visitable_s[i] and visitable_g[i] for i in range(N)]

inf = float("inf")

d = [inf] * N

d[0] = 0



# Bellman-Ford

for i in range(N):

    for a, b, c in ABC:

        if not visitable[a] or not visitable[b]:

            continue

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

            continue

        if i == N - 1:

            print((-1))

            exit()

        d[b] = d[a] + c

ans = d[N - 1]

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])))

from collections import deque

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))
# preprocess
to = [[] for _ in range(N)]
fr = [[] for _ in range(N)]
for a, b, c in ABC:
    to[a].append(b)
    fr[b].append(a)
visitable_s = [False] * N
q = deque()
q.append(0)
visitable_s[0] = True
while len(q):
    a = q.pop()
    for b in to[a]:
        if not visitable_s[b]:
            visitable_s[b] = True
            q.append(b)
visitable_g = [False] * N
q = deque()
q.append(N - 1)
visitable_g[N - 1] = True
while len(q):
    a = q.pop()
    for b in fr[a]:
        if not visitable_g[b]:
            visitable_g[b] = True
            q.append(b)
visitable = [visitable_s[i] and visitable_g[i] for i in range(N)]
inf = float("inf")
d = [inf] * N
d[0] = 0
# Bellman-Ford
for i in range(N):
    for a, b, c in ABC:
        if not visitable[a] or not visitable[b]:
            continue
        if d[b] <= d[a] + c:
            continue
        if i == N - 1:
            print((-1))
            exit()
        d[b] = d[a] + c
ans = d[N - 1]
print((max(0, -d[N - 1])))

+from collections import deque + +# preprocess +to = [[] for _ in range(N)] +fr = [[] for _ in range(N)] +for a, b, c in ABC: +    to[a].append(b) +    fr[b].append(a) +visitable_s = [False] * N +q = deque() +q.append(0) +visitable_s[0] = True +while len(q): +    a = q.pop() +    for b in to[a]: +        if not visitable_s[b]: +            visitable_s[b] = True +            q.append(b) +visitable_g = [False] * N +q = deque() +q.append(N - 1) +visitable_g[N - 1] = True +while len(q): +    a = q.pop() +    for b in fr[a]: +        if not visitable_g[b]: +            visitable_g[b] = True +            q.append(b) +visitable = [visitable_s[i] and visitable_g[i] for i in range(N)] +        if not visitable[a] or not visitable[b]: +            continue +        if i == N - 1: +            print((-1)) +            exit() -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]))) +print((max(0, -d[N - 1])))