import sys

sys.setrecursionlimit(10**5)





def dfs(s):

    for i in to[s]:

        if not toflag[i]:

            toflag[i]=True

            dfs(i)





def rdfs(s):

    for i in ot[s]:

        if not otflag[i]:

            otflag[i]=True

            rdfs(i)





def bellman_ford():

    for i in range(n):

        upd=False

        for a,b,c in edges:

            if d[b]>d[a]+c:

                upd=True

                d[b]=d[a]+c     

        if not upd:

            break

        if i == n-1:

            print((-1))

            exit()





def main():



    for i in range(m):

        a,b,c=[int(x)-1 for x in input().split()]

        edges.append([a,b,-(c+1-p)])

        to[a].append(b)

        ot[b].append(a)



    toflag[0]=True

    otflag[n-1]=True

    dfs(0) # check for 0 to i path

    rdfs(n-1) # check for n-1 to i path

 

    for i in range(m):

        a,b,c=edges[i]

        if toflag[a] and otflag[a] and toflag[b] and otflag[b]: continue;

        edges[i]=[0,0,0]



    d[0]=0

    bellman_ford()

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







if __name__=='__main__':

    n,m,p=list(map(int,input().split()))

    edges=[]

    to=[[] for i in range(n)]

    ot=[[] for i in range(n)]

    toflag=[False]*n

    otflag=[False]*n

    d=[10**9]*n

    main()
import sys

import numpy as np

from scipy.sparse.csgraph import bellman_ford, NegativeCycleError

from scipy.sparse import csr_matrix



sys.setrecursionlimit(10**5)



def dfs(s):

  for u in to[s]:

    if not toflag[u]:

      toflag[u]=True

      dfs(u)



def rdfs(s):

  for u in ot[s]:

    if not otflag[u]:

      otflag[u]=True

      rdfs(u)



def main():

  for i in range(m):

    a,b,c=[int(x)-1 for x in input().split()]

    edges[i]=[a,b,-(c+1-p)]

    to[a].append(b)

    ot[b].append(a)

  

  toflag[0]=True

  otflag[-1]=True

  dfs(0)

  rdfs(n-1)

  

  dic={}

  for a,b,c in edges:

    if toflag[a] and otflag[b]:

      if (a,b) in list(dic.keys()):

        dic[(a,b)]=min(dic[(a,b)],c)

      else:

        dic[(a,b)]=c

        

  row=[]

  col=[]

  data=[]

  for (a,b),c in list(dic.items()):

      row.append(a)

      col.append(b)

      data.append(c)

  g=csr_matrix((data,(row,col)), shape=(n,n))

  try:

    d=bellman_ford(g,indices=0).astype(int)

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

  except NegativeCycleError:

    print((-1))



    

if __name__=='__main__':

  n,m,p=list(map(int,input().split()))

  edges=[[] for i in range(m)]

  to=[[] for i in range(n)]

  ot=[[] for i in range(n)]

  toflag=[False]*n

  otflag=[False]*n

  main()
import sys

sys.setrecursionlimit(10**5)


def dfs(s):
    for i in to[s]:
        if not toflag[i]:
            toflag[i] = True
            dfs(i)


def rdfs(s):
    for i in ot[s]:
        if not otflag[i]:
            otflag[i] = True
            rdfs(i)


def bellman_ford():
    for i in range(n):
        upd = False
        for a, b, c in edges:
            if d[b] > d[a] + c:
                upd = True
                d[b] = d[a] + c
        if not upd:
            break
        if i == n - 1:
            print((-1))
            exit()


def main():
    for i in range(m):
        a, b, c = [int(x) - 1 for x in input().split()]
        edges.append([a, b, -(c + 1 - p)])
        to[a].append(b)
        ot[b].append(a)
    toflag[0] = True
    otflag[n - 1] = True
    dfs(0)  # check for 0 to i path
    rdfs(n - 1)  # check for n-1 to i path
    for i in range(m):
        a, b, c = edges[i]
        if toflag[a] and otflag[a] and toflag[b] and otflag[b]:
            continue
        edges[i] = [0, 0, 0]
    d[0] = 0
    bellman_ford()
    print((max(0, -d[-1])))


if __name__ == "__main__":
    n, m, p = list(map(int, input().split()))
    edges = []
    to = [[] for i in range(n)]
    ot = [[] for i in range(n)]
    toflag = [False] * n
    otflag = [False] * n
    d = [10**9] * n
    main()

import sys
import numpy as np
from scipy.sparse.csgraph import bellman_ford, NegativeCycleError
from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**5)


def dfs(s):
    for u in to[s]:
        if not toflag[u]:
            toflag[u] = True
            dfs(u)


def rdfs(s):
    for u in ot[s]:
        if not otflag[u]:
            otflag[u] = True
            rdfs(u)


def main():
    for i in range(m):
        a, b, c = [int(x) - 1 for x in input().split()]
        edges[i] = [a, b, -(c + 1 - p)]
        to[a].append(b)
        ot[b].append(a)
    toflag[0] = True
    otflag[-1] = True
    dfs(0)
    rdfs(n - 1)
    dic = {}
    for a, b, c in edges:
        if toflag[a] and otflag[b]:
            if (a, b) in list(dic.keys()):
                dic[(a, b)] = min(dic[(a, b)], c)
            else:
                dic[(a, b)] = c
    row = []
    col = []
    data = []
    for (a, b), c in list(dic.items()):
        row.append(a)
        col.append(b)
        data.append(c)
    g = csr_matrix((data, (row, col)), shape=(n, n))
    try:
        d = bellman_ford(g, indices=0).astype(int)
        print((max(0, -d[-1])))
    except NegativeCycleError:
        print((-1))


if __name__ == "__main__":
    n, m, p = list(map(int, input().split()))
    edges = [[] for i in range(m)]
    to = [[] for i in range(n)]
    ot = [[] for i in range(n)]
    toflag = [False] * n
    otflag = [False] * n
    main()

+import numpy as np +from scipy.sparse.csgraph import bellman_ford, NegativeCycleError +from scipy.sparse import csr_matrix -    for i in to[s]: -        if not toflag[i]: -            toflag[i] = True -            dfs(i) +    for u in to[s]: +        if not toflag[u]: +            toflag[u] = True +            dfs(u) -    for i in ot[s]: -        if not otflag[i]: -            otflag[i] = True -            rdfs(i) - - -def bellman_ford(): -    for i in range(n): -        upd = False -        for a, b, c in edges: -            if d[b] > d[a] + c: -                upd = True -                d[b] = d[a] + c -        if not upd: -            break -        if i == n - 1: -            print((-1)) -            exit() +    for u in ot[s]: +        if not otflag[u]: +            otflag[u] = True +            rdfs(u) -        edges.append([a, b, -(c + 1 - p)]) +        edges[i] = [a, b, -(c + 1 - p)] -    otflag[n - 1] = True -    dfs(0)  # check for 0 to i path -    rdfs(n - 1)  # check for n-1 to i path -    for i in range(m): -        a, b, c = edges[i] -        if toflag[a] and otflag[a] and toflag[b] and otflag[b]: -            continue -        edges[i] = [0, 0, 0] -    d[0] = 0 -    bellman_ford() -    print((max(0, -d[-1]))) +    otflag[-1] = True +    dfs(0) +    rdfs(n - 1) +    dic = {} +    for a, b, c in edges: +        if toflag[a] and otflag[b]: +            if (a, b) in list(dic.keys()): +                dic[(a, b)] = min(dic[(a, b)], c) +            else: +                dic[(a, b)] = c +    row = [] +    col = [] +    data = [] +    for (a, b), c in list(dic.items()): +        row.append(a) +        col.append(b) +        data.append(c) +    g = csr_matrix((data, (row, col)), shape=(n, n)) +    try: +        d = bellman_ford(g, indices=0).astype(int) +        print((max(0, -d[-1]))) +    except NegativeCycleError: +        print((-1)) -    edges = [] +    edges = [[] for i in range(m)] -    d = [10**9] * n