#n = gets.chomp.to_i
n, m, P = gets.chomp.split().map(&:to_i)
edges = readlines.map{|m| m.chomp.split.map(&:to_i)}

edges.map!{|a,b,c| [a,b,(c-P)*-1]}
p edges

ehash = {}
edges.each do |a,b,c|
  ehash[a] ||= []
  ehash[a].push b
end

# remove loop
q = [1]
visited_v = []
toberemoved_edges = []
until q.empty?
  vol = q.shift
  next unless ehash.has_key? vol
  new_visited_v = []
  ehash[vol].each do |v|
    if visited_v[v]
      toberemoved_edges.push [vol, v]
    else
      new_visited_v[v] = true
      q.push v
    end
  end
  visited_v += new_visited_v
end

p visited_v
p toberemoved_edges
exit
# v_num :: Voltex数
# edges :: [[from, to, cost], [from, to, cost], ...]
# s :: start
def shortest_path(v_num, edges, s)
  d = Array.new(v_num, Float::INFINITY)
  d[s - 1] = 0

  while true
    update = false

    edges.each do |e|
      from, to, cost = e

      if d[from - 1] != Float::INFINITY && d[to - 1] > (d[from - 1] + cost)
        d[to - 1] = (d[from - 1] + cost)
        update = true
      end
    end
    break if !update
  end
  d
end

p paths = shortest_path(n, edges, 1)
puts paths.last * -1
