{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ViewPatterns          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Builder     as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Internal    as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import qualified System.IO                   as IO
import           Unsafe.Coerce

main :: IO ()
main = do
    [n, m, p] <- map read.words <$> getLine :: IO [Int]
    edges <- U.unfoldrN m parseInt3 <$> C.getContents
    print $ solve n p edges

solve :: Int -> Int -> U.Vector (Int, Int, Int) -> Int
solve n p edges = case spfa 0 gr costs of
    Just dist -> max 0.negate $ U.last dist
    Nothing -> -1
  where
    !visited = reachable (n - 1)
        . buildDirectedGraph n
        . U.map (\(src, dst) -> (dst - 1, src - 1))
        . uncurry U.zip
        . (\(x,y,_) -> (x, y))
        $ U.unzip3 edges
    gr = buildDirectedGraph n
        . U.filter (\(src, dst)-> U.unsafeIndex visited src && U.unsafeIndex visited dst)
        . U.map (\(src, dst) -> (src - 1, dst - 1))
        . uncurry U.zip
        . (\(x,y,_) -> (x, y))
        $ U.unzip3 edges
    costs = buildEdgeContext n
        . U.filter (\(src, dst, _)-> U.unsafeIndex visited src && U.unsafeIndex visited dst)
        $ U.map (\(src, dst, cost) -> (src - 1, dst - 1, p - cost)) edges

reachable :: Vertex -> Graph -> U.Vector Bool
reachable root gr = U.create $ do
    let n = numVertices gr
    visited <- UM.replicate n False
    queue <- newQueueM
    UM.write visited root True
    enqueueM root queue
    fix $ \loop -> do
        dequeueM queue >>= \case
            Just v -> do
                U.forM_ (adjacent gr v) $ \nv -> do
                    fnv <- UM.unsafeRead visited nv
                    unless fnv $ do
                        UM.unsafeWrite visited nv True
                        enqueueM nv queue
            Nothing -> return ()
    return visited

inf :: Int
inf = 0x3f3f3f3f

spfa :: Vertex -> Graph -> U.Vector Int -> Maybe (U.Vector Int)
spfa root gr costs = runST $ do
    let !numV = numVertices gr
    dist <- UM.replicate numV inf
    inQueue <- UM.replicate numV False
    visit <- UM.replicate numV 0
    queue <- newQueueM

    UM.unsafeWrite dist root 0
    UM.unsafeWrite inQueue root True
    UM.unsafeModify visit (+1) root
    enqueueM root queue

    fix $ \loop -> do
        hd <- dequeueM queue
        case hd of
            Just v -> do
                UM.unsafeWrite inQueue v False
                count <- UM.unsafeRead visit v
                if count <= numV
                then do
                    dv <- UM.unsafeRead dist v
                    U.forM_ (adjacentWithCtx gr costs v) $ \(nv, v2nv) -> do
                        let !dnv = dv + v2nv
                        old <- UM.unsafeRead dist nv
                        when (dnv < old) $ do
                            UM.unsafeWrite dist nv dnv
                            inQ <- UM.unsafeRead inQueue nv
                            unless inQ $ do
                                UM.unsafeWrite inQueue nv True
                                UM.unsafeModify visit (+1) nv
                                enqueueM nv queue
                    loop
                else return Nothing
            Nothing -> Just <$> U.unsafeFreeze dist

buildEdgeContext :: (U.Unbox e) => Int -> U.Vector (Vertex, Vertex, e) -> U.Vector e
buildEdgeContext n edges = U.create $ do
    offset <- U.unsafeThaw
        . U.scanl' (+) (n + 1)
        . U.unsafeAccumulate (+) (U.replicate n 0)
        . U.map (flip (,) 1)
        . (\(x, _, _) -> x)
        $ U.unzip3 edges
    gr <- UM.new (UM.length offset + U.length edges)
    U.forM_ edges $ \(src, dst, e) -> do
        pos <- UM.unsafeRead offset src
        UM.unsafeWrite offset src (pos + 1)
        UM.unsafeWrite gr pos e
    return gr

adjacentWithCtx :: (U.Unbox e) => Graph -> U.Vector e -> Int -> U.Vector (Vertex, e)
adjacentWithCtx gr ctx v = U.unsafeSlice offset len $ U.zip gr ctx
  where
    offset = U.unsafeIndex gr v
    len = U.unsafeIndex gr (v + 1) - offset

-------------------------------------------------------------------------------
type Vertex = Int
type Edge = (Vertex, Vertex)
type Graph = U.Vector Int

buildDirectedGraph :: Int -> U.Vector Edge -> Graph
buildDirectedGraph n edges = U.create $ do
    offset <- U.unsafeThaw
        . U.scanl' (+) (n + 1)
        . U.unsafeAccumulate (+) (U.replicate n 0)
        . U.map (flip (,) 1)
        . fst
        $ U.unzip edges
    gr <- UM.replicate (UM.length offset + U.length edges) 0
    U.forM_ (U.generate (n + 1) id) $ \i ->
        UM.unsafeRead offset i >>= UM.unsafeWrite gr i
    U.forM_ edges $ \(src, dst) -> do
        pos <- UM.unsafeRead offset src
        UM.unsafeWrite offset src (pos + 1)
        UM.unsafeWrite gr pos dst
    return gr

buildUndirectedGraph :: Int -> U.Vector Edge -> Graph
buildUndirectedGraph n edges
    = buildDirectedGraph n (edges U.++ U.map swap edges)

numVertices :: Graph -> Int
numVertices gr = U.head gr - 1

numEdges :: Graph -> Int
numEdges gr = U.length gr - U.head gr

vertices :: Graph -> U.Vector Vertex
vertices = flip U.generate id . numVertices

adjacent :: Graph -> Int -> U.Vector Vertex
adjacent gr v = U.unsafeSlice offset len gr
  where
    offset = U.unsafeIndex gr v
    len = U.unsafeIndex gr (v + 1) - offset

data VecQueue s a = VecQueue
    { queueInfo :: !(UM.MVector s Int)
    , queueData :: !(UM.MVector s a)
    }

withCapacityQ
    :: (PrimMonad m, UM.Unbox a)
    => Int -> m (VecQueue (PrimState m) a)
withCapacityQ n
    = VecQueue <$> UM.replicate 2 0 <*> UM.unsafeNew n

newQueueM :: (PrimMonad m, UM.Unbox a) => m (VecQueue (PrimState m) a)
newQueueM = withCapacityQ (1024 * 1024)

runQueue
    :: (PrimMonad m, UM.Unbox a)
    => VecQueue (PrimState m) a -> m (U.Vector a)
runQueue (VecQueue info q) = do
    len <- UM.unsafeRead info 1
    U.unsafeFreeze $ UM.take len q

lengthQ :: (PrimMonad m, UM.Unbox a) => VecQueue (PrimState m) a -> m Int
lengthQ (VecQueue info q)
    = (-) <$> UM.unsafeRead info 1 <*> UM.unsafeRead info 0

dequeueM :: (PrimMonad m, UM.Unbox a) => VecQueue (PrimState m) a -> m (Maybe a)
dequeueM (VecQueue info q) = do
    h <- UM.unsafeRead info 0
    t <- UM.unsafeRead info 1
    if h < t
    then do
        UM.unsafeWrite info 0 (h + 1)
        pure <$> UM.unsafeRead q h
    else return Nothing
{-# INLINE dequeueM #-}

enqueueM :: (PrimMonad m, UM.Unbox a) => a -> VecQueue (PrimState m) a -> m ()
enqueueM x (VecQueue info q) = do
    t <- UM.unsafeRead info 1
    UM.unsafeWrite q t x
    UM.unsafeWrite info 1 (t + 1)
{-# INLINE enqueueM #-}

type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
    (,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt4 :: Parser (Int, Int, Int, Int)
parseInt4 = runStateT $
    (,,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)