Language: C++

#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<int(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
constexpr int64_t INF = INT64_C(1000000000000000000);

using Array = vector<int64_t>;
using Matrix = vector<Array>;

Matrix mul(const Matrix& lhs, const Matrix& rhs) {
  int r = lhs.size();
  Matrix res(r, Array(r, -INF));
  REP(i,r) REP(k,r) REP(j,r) {
    res[i][j] = max(res[i][j], lhs[i][k] + rhs[k][j]);
  }
  return res;
}

Matrix pow(const Matrix& mat, int64_t index) {
  if (index == 1) return mat;
  if ((index % 2) == 1) {
    return mul(mat, pow(mat, index-1));
  }
  return pow(mul(mat, mat), index/2);
}

int main() {
  int64_t v,e,k;
  cin>>v>>e>>k;
  Matrix mat(v, Array(v, -INF));
  REP(i,e) {
    int64_t s,t,c;
    cin>>s>>t>>c;
    mat[s][t] = max(mat[s][t], c);
  }
  vector<Matrix> vmat;
  Matrix m(v, Array(v, -INF));
  REP(i,v) m[i][i] = 0;
  vmat.push_back(m);
  REP(i,max(100,v)) {
    m = mul(mat, m);
    vmat.push_back(m);
  }
  int64_t mx = -INF;
  int64_t hi = k;
  REP(idx,v)REP(i,v)REP(j,v) {
    if (vmat[idx+1][i][j] >= k) {
      if (idx < hi) {
        hi = idx+1;
        mx = max(mx, vmat[idx+1][i][j]);
      }
    }
  }
  int mx2 = 0;
  REP(i,v)REP(j,v) mx2 = max(mx2, vmat[v][i][j]);
  if (mx2 > 0 && mx < k) {
    hi = k;
    int64_t lo = v;
    while (hi - lo > 1) {
      int64_t mid = (hi + lo) / 2;
      auto pmat = pow(mat, mid);
      int64_t mx = -INF;
      REP(i,v)REP(j,v) mx = max(mx, pmat[i][j]);
      if (mx < 0) {
        hi = mid;
      } else if (mx >= k) {
        hi = mid;
      } else {
        lo = mid;
      }
    }
  }
  auto pmat = pow(mat, hi);
  mx = -INF;
  REP(i,v)REP(j,v) mx = max(mx, pmat[i][j]);
  if (mx < k) {
    cout << -1 << endl;
    return 0;
  } 
  cout << hi << endl;
  if (hi > 100) {
    return 0;
  }
  int s=0,t=0;
  REP(i,v)REP(j,v) {
    if (pmat[i][j] == mx) {
      s = i;
      t = j;
    }
  }
  vector<int> res;
  res.push_back(t);
  for (int i = hi-1; i >= 0; --i) {
    int nt=0;
    int64_t nmx=0;
    REP(j,v) {
      if (vmat[i][s][j] + mat[j][t] == mx) {
        nt = j;
        nmx = vmat[i][s][j];
      }
    }
    t = nt;
    mx = nmx;
    res.push_back(t);
  }
  reverse(ALL(res));
  REP(i,res.size()) {
    if (i) cout << ' ';
    cout << res[i];
  }
  cout << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:12: error: no matching function for call to 'max(int, int64_t&)'
   42 |   REP(i,max(100,v)) {
      |         ~~~^~~~~~~
a.cc:2:40: note: in definition of macro 'FOR'
    2 | #define FOR(i,k,n) for(int i=(k);i<int(n);++i)
      |                                        ^
a.cc:42:3: note: in expansion of macro 'REP'
   42 |   REP(i,max(100,v)) {
      |   ^~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:42:12: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'int64_t' {aka 'long int'})
   42 |   REP(i,max(100,v)) {
      |         ~~~^~~~~~~
a.cc:2:40: note: in definition of macro 'FOR'
    2 | #define FOR(i,k,n) for(int i=(k);i<int(n);++i)
      |                                        ^
a.cc:42:3: note: in expansion of macro 'REP'
   42 |   REP(i,max(100,v)) {
      |   ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:42:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   42 |   REP(i,max(100,v)) {
      |         ~~~^~~~~~~
a.cc:2:40: note: in definition of macro 'FOR'
    2 | #define FOR(i,k,n) for(int i=(k);i<int(n);++i)
      |                                        ^
a.cc:42:3: note: in expansion of macro 'REP'
   42 |   REP(i,max(100,v)) {
      |   ^~~
a.cc:57:29: error: no matching function for call to 'max(int&, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type&)'
   57 |   REP(i,v)REP(j,v) mx2 = max(mx2, vmat[v][i][j]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:57:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   57 |   REP(i,v)REP(j,v) mx2 = max(mx2, vmat[v][i][j]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:57:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   57 |   REP(i,v)REP(j,v) mx2 = max(mx2, vmat[v][i][j]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~