require 'tsort'
class Hash
  include TSort
  alias tsort_each_node each_key
  def tsort_each_child(u, &block)
    self[u].each_key(&block) if self[u]
  end
end

n, m, k = gets.split.map(&:to_i)

matrices = []
a = Array.new(n).map { Array.new(n, -10*k) }
(0..n-1).each {|i| a[i][i] = 0 }
g = Hash[(0..n-1).map {|i| [i, Hash.new(0)] }]
m.times do
  i, j, c = gets.split.map(&:to_i)
  a[i][j] = c if c > a[i][j]
  g[i][j] = c if c > g[i][j]
end
matrices << a

begin
  # DAG
  g.tsort
  l = Marshal.load(Marshal.dump(g))
  d = 1
  score = (l.values.map {|h| h.values.max || -1 }.max || -1)
  until score >= k || l.empty?
    d += 1
    new_l = {}
    g.each do |i, h|
      h.each do |j, c1|
        if l[j]
          l[j].each do |k, c2|
            new_l[i] ||= Hash.new(0)
            new_l[i][k] = c1 + c2 if new_l[i][k] < c1 + c2
          end
        end
      end
    end
    l = new_l
    score = (l.values.map {|h| h.values.max || -1 }.max || -1)
  end

  if l.empty?
    p -1
    exit
  end
  p d

  s = t = nil
  (0..n-1).each do |i|
    (0..n-1).each do |j|
      if l[i] && l[i][j] == score
        s = i
        t = j
        break
      end
    end
    break if s
  end
  
  paths = (0..n-1).map {|i| i == t ? [t] : nil }
  lens = (0..n-1).map {|i| i == t ? 0 : -Float::INFINITY }
  d.times do
    new_paths = Array.new(n)
    new_lens = Array.new(n, -Float::INFINITY)
    (0..n-1).each do |i|
      j = g[i].keys.max_by {|j| g[i][j] + lens[j] }
      if j
        new_lens[i] = g[i][j] + lens[j]
        new_paths[i] = (paths[j] ? [i] + paths[j] : nil)
      end
    end
    paths = new_paths
    lens = new_lens
  end
  puts paths[s] * " "

  exit
rescue TSort::Cyclic
  # do nothing
end


until matrices[-1].map {|row| row.max }.max >= k
  a = matrices[-1]
  b = Array.new(n).map { Array.new(n, -10*k) }
  (0..n-1).each do |i|
    (0..n-1).each do |j|
      (0..n-1).each do |k|
        x = a[i][k] + a[k][j]
        b[i][j] = x if x > b[i][j]
      end
    end
  end
  matrices << b
end

if matrices.size == 1
  a = matrices[0]
  d = 1
else
  d = 1 << matrices.size - 2
  a = matrices[-2]
  (matrices.size - 2).downto(0) do |i|
    b = matrices[i]
    c = Array.new(n).map { Array.new(n, -10*k) }
    (0..n-1).each do |i|
      (0..n-1).each do |j|
        (0..n-1).each do |k|
          x = a[i][k] + b[k][j]
          c[i][j] = x if x > c[i][j]
        end
      end
    end
    if c.map {|row| row.max }.max < k
      a = c
      d += (1 << i)
    end
  end
end

score = a.map {|row| row.max }.max
if score < k
  d += 1
  c = Array.new(n).map { Array.new(n, -Float::INFINITY) }
  (0..n-1).each do |i|
    (0..n-1).each do |j|
      c[i][j] = (0..n-1).map {|k| a[i][k] + matrices[0][k][j] }.max
    end
  end
  a = c
  score = a.map {|row| row.max }.max
end
p d

if d <= 1000
  s = t = nil
  (0..n-1).each do |i|
    (0..n-1).each do |j|
      if a[i][j] == score
        s, t = i, j
        break
      end
    end
    break if s
  end

  paths = (0..n-1).map {|i| i == t ? [t] : nil }
  lens = (0..n-1).map {|i| i == t ? 0 : -Float::INFINITY }
  d.times do
    new_paths = Array.new(n)
    new_lens = Array.new(n, -Float::INFINITY)
    (0..n-1).each do |i|
      j = g[i].keys.max_by {|j| g[i][j] + lens[j] }
      if j
        new_lens[i] = g[i][j] + lens[j]
        new_paths[i] = (paths[j] ? [i] + paths[j] : nil)
      end
    end
    paths = new_paths
    lens = new_lens
  end
  puts paths[s] * " "
end



Measured memory_bytes: 24556