using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace A
{
    class StartingPoint
    {
        static void Main(string[] args)
        {
            if (args?.Any() == true)
            {
                var assembly = Assembly.GetEntryAssembly();
                var resourceName = "AtCoderCSharp.In.txt";
                var stream = assembly.GetManifestResourceStream(resourceName);
                var streamReader = new StreamReader(stream, Encoding.UTF8);
                var str = streamReader.ReadToEnd();
                var textReader = new StringReader(str);
                Console.SetIn(textReader);
            }

            try
            {
                foreach (var s in new Program().Solve())
                {
                    Console.WriteLine(s);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                if (args?.Any() != true)
                    throw e;
            }

            if (args?.Any() == true)
                Console.ReadKey();
        }
    }

    class Program
    {
        public List<int> ScanInts(int count) => Enumerable.Range(0, count).Select(_ => ScanInt).ToList();
        public List<int> ScanInts(long count) => ScanInts((int)count);
        public List<long> ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList();
        public List<long> ScanLongs(long count) => ScanLongs((int)count);
        public int ScanInt => int.Parse(Str);
        public long Scan => long.Parse(Str);
        public double ScanDouble => (double)Scan;

        StringBuilder sb = new StringBuilder();

        public string Str => ScanStr();
        public string ScanStr()
        {
            sb.Clear();

            int r = 0;
            bool? b = null;
            do
            {
                r = Console.Read();
                b = IsBreak(r);
            } while (b == true);

            if (b == null)
                throw new Exception("input error: unexpected end of stream");

            do
            {
                sb.Append((char)r);
                r = Console.Read();
                b = IsBreak(r);
            } while (b == false);

            return sb.ToString();
        }

        bool? IsBreak(int c)
        {
            switch (c)
            {
                case -1:
                    return null;
                case (int)' ':
                case (int)'\n':
                case (int)'\r':
                    return true;
                default:
                    return false;
            }
        }

        public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count);
        public IEnumerable<int> Loop(int from, int to) => Enumerable.Range(from, to - from + 1);

        public IEnumerable<long> Loop(long count) => Loop(0, count - 1);
        public IEnumerable<long> Loop(long from, long to)
        {
            for (long i = from; i <= to; i++)
                yield return i;
        }

        public string YesNo(bool isYes) => isYes ? "Yes" : "No";

        public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts);

        public class Vertex
        {
            public long Distance { get; set; }

            public Vertex()
            {
                Distance = long.MaxValue;
            }
        }

        public class Edge
        {
            public int From { get; private set; }
            public int To { get; private set; }
            public long Weight { get; private set; }

            public Edge(int from, int to, long weight)
            {
                From = from;
                To = to;
                Weight = weight;
            }
        }

        void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths)
        {
            if (reached.Contains(origin))
                return;

            reached.Add(origin);

            if (paths.ContainsKey(origin) == false)
                return;

            foreach (var p in paths[origin])
                GetReachable(p, ref reached, ref paths);
        }

        /// <summary>
        /// null: 負の無限大
        /// long.MaxValue: たどり着けない
        /// その他: 距離
        /// </summary>
        public long? BellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest)
        {
            var forwards = rawEdges.GroupBy(x => x.From).ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
            var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(x => x.Key, x => x.Select(xs => xs.From).ToArray());

            var fromSource = new HashSet<int>();
            var toDest = new HashSet<int>();

            GetReachable(source, ref fromSource, ref forwards);
            GetReachable(dest, ref toDest, ref reverses);

            var edges = rawEdges
                .Where(e => fromSource.Contains(e.From))
                .Where(e => fromSource.Contains(e.To))
                .Where(e => toDest.Contains(e.From))
                .Where(e => toDest.Contains(e.To))
                .ToArray();

            // initialize distances
            var vertices = new List<Vertex>();
            for (int i = 0; i < vertexCount; i++)
                vertices.Add(new Vertex());
            vertices[source].Distance = 0L;

            // update distances
            for (int i = 0; i < vertices.Count; i++)
            {
                foreach (var e in edges)
                {
                    var from = vertices[e.From];
                    var to = vertices[e.To];

                    if (from.Distance == long.MaxValue)
                        continue;

                    var newDistance = from.Distance + e.Weight;
                    if (to.Distance > newDistance)
                    {
                        to.Distance = newDistance;
                    }
                }
            }

            // check negative cycle
            foreach (var e in edges)
            {
                var from = vertices[e.From];
                var to = vertices[e.To];

                if (from.Distance + e.Weight < to.Distance)
                    return null;
            }

            return vertices[dest].Distance;
        }

        public IEnumerable<string> Solve()
        {
            var n = ScanInt;
            var m = Scan;
            var p = Scan;
            var edges = new List<Edge>();

            foreach (var i in Loop(m))
            {
                var a = ScanInt - 1;
                var b = ScanInt - 1;
                var c = -(Scan - p);

                edges.Add(new Edge(a, b, c));
            }

            long? res = BellmanFord(n, edges, 0, n - 1);
            long rrr =
                res == null ? -1 : res.Value < 0 ? -res.Value : 0;

            yield return rrr.ToString();
        }
    }
}

Measured memory_bytes: 17120