Problem:
Sports Days 2.0
会津大学附属小学校（会津大小）は日本有数の競技プログラマー養成校として有名である。
もちろん、運動会に参加しているときでさえアルゴリズムの修行を欠かせない。
競技プログラミング部部長のあなたはもちろんこの大会でも勝利したい。
今回はある競技に注目する。
ある競技とは会津大小で行われている伝統的な競技だ。
校庭にコーンが
V
個置いてある。
コーンのいくつかのペアは白線で描かれた矢印で結ばれている。
矢印の先は片側だけについており、整数が併記されている。
同じコーンのペアがの複数の矢印に結ばれている場合もある。
競技者は任意にコーンを選び、移動開始する。
移動は競技者がいるコーンから矢印の上をその向きに移動し、次のコーンへ移る。
同じコーン、同じ矢印を何度も辿っても良い。
競技者はコーンからコーンへの移動後、さらに移動するか移動を終了をするかを選択することができる。
この競技の目的は矢印を辿ることにより、スコアをK以上にすることである。
スコアは矢印を辿る度に併記された整数値が加算されていく。
より少ない経由する矢印の本数でスコアを
K
以上にした競技者が勝利となる。
矢印が同じ本数の場合はより高いスコアの競技者が勝利となる。
このルールで最適な動きを競技者が行った場合、何本の矢印を経由すべきか出力せよ。
また、経由した矢印の数が100本以下の場合、経由すべきコーンを順にすべて出力せよ。
最適な動きが複数存在する場合があるが、どの動きの結果を出力しても良い。
スコアを
K
以上にする動きが存在しない場合は-1を出力せよ。
また、コーンにはすべて0から
V-1
までの番号が振られており、
色はすべて緑色（意味深）である。
Input
入力は以下の形式で与えられる。
V
E
K
v
11
v
12
c
1
...
v
i1
v
i2
c
i
...
v
E1
v
E2
c
E
ここで、
V
はコーンの数
E
は矢印の数
v
i,1
は矢印
i
の始点のコーン番号
v
i2
は矢印
i
の終点のコーン番号
c
i
は矢印に併記されている整数
である。
Constraints
入力は以下の条件を満たす。
入力はすべて整数
2≤V≤150
0≤E≤V×V
0<K≤10
6
0≤ v
i1
, v
i2
< V      (0<i≤E)
v
i1
≠ v
i2
(0<i≤E)
0<c
i
≤ 100           (0<i≤E)
v
i1
= v
j1
かつ
v
i2
= v
j2
(i ≠ j, 0<i,j≤E)
となるような
i, j
が含まれる入力も存在する。
Output
出力は2行からなる。
1行目　最適な動きを行った場合の経由する矢印の本数で出力
2行目　経由すべきコーンの番号を経由する順番に空白区切りで出力
最適な動きが複数存在する場合があるが、どの動きの結果を出力しても良い。
経由すべき矢印の本数が100本を越える場合、2行目は出力してはいけない。
スコアを
K
以上にする最適な動きが存在しない場合は-1を1行目に出力し、
2行目に何も出力してはいけない。
Sample Input 1
3 9 89
2 0 2
1 0 3
2 0 1
2 0 3
0 1 1
0 1 2
1 2 3
0 1 1
1 0 2
Output for the Sample Input 1
34
1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 0
Sample Input 2
2 0 1
Output for the Sample Input 2
-1
Sample Input 3
7 8 4000
0 1 1
1 0 1
1 2 2
2 3 2
3 4 2
5 4 3
3 5 4
5 6 5
Output for the Sample Input 3
3991

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF32 = 1 << 30;
constexpr ll INF64 = 1LL << 62;
constexpr ll MOD = 1000000007;
// constexpr ll MOD = 998244353;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-10;
const double PI = acos(-1);

#define ALL(v) (v).begin(),(v).end()
#define REP(i,n) for(int i=0,i_len=n; i<i_len; ++i)

template<typename T1,typename T2> bool chmax(T1 &a, T2 b) { if (a<b) { a=b; return 1; } return 0; }
template<typename T1,typename T2> bool chmin(T1 &a, T2 b) { if (b<a) { a=b; return 1; } return 0; }

ll V, E, K;
const int T = 29;
ll C[150][150][T+1];

void init(){
    for(int t=0;t<T;t++){
        REP(i,V) REP(j,V) REP(k,V){
            if(C[i][k][t] >= 0 && C[k][j][t] >= 0){
                chmax(C[i][j][t+1], C[i][k][t]+C[k][j][t]);
            }
        }
    }
}

ll calc(ll n){
    ll res[150][150]{};
    REP(i,V) fill(res[i],res[i]+V,-INF64);
    REP(i,V) res[i][i] = 0;
    for(int t=0;t<T;t++){
        if((n>>t)&1){
            ll tmp[150][150]{};
            REP(i,V) fill(tmp[i],tmp[i]+V,-INF64);
            REP(i,V) REP(j,V) REP(k,V){
                if(C[k][j][t] >= 0){
                    chmax(tmp[i][j], res[i][k]+C[k][j][t]);
                }
            }
            REP(i,V) REP(j,V) chmax(res[i][j],tmp[i][j]);
        }
    }
    ll ma = -1;
    REP(i,V) REP(j,V) chmax(ma, res[i][j]);
    // cout << n << endl;
    // REP(i,V){
    //     REP(j,V){
    //         cout << res[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    return ma;
}

vector<int> reconstruct(int n){
    ll rev[150][101]{}, scr[150]{};
    for(int t=0;t<n;t++){
        ll tmp[150]{};
        fill(tmp,tmp+V,-INF32);
        REP(i,V) REP(j,V){
            if(C[j][i][0]>=0 && chmax(tmp[i], scr[j]+C[j][i][0])){
                rev[i][t+1] = j;
            }
        }
        REP(i,V) scr[i] = tmp[i];
    }
    ll maxidx = -1, ma = -1;
    REP(i,V){
        if(chmax(ma, scr[i])) maxidx = i;
    }
    vector<int> v;
    v.push_back(maxidx);
    for(int t=n,now=maxidx;t>0;t--){
        v.push_back(rev[now][t]);
        now = rev[now][t];
    }
    reverse(ALL(v));
    return v;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    cin >> V >> E >> K;
    REP(i,V) REP(j,V) REP(k,T+1) C[i][j][k] = (i==j?0:-INF64);
    REP(i,E){
        int u, v, c;
        cin >> u >> v >> c;
        chmax(C[u][v][0], c);
    }
    init();
    ll ok = 1<<(T), ng = 0;
    while(abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        if(calc(mid) >= K){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    if(ok <= 100){
        cout << ok << endl;
        vector<int> ans = reconstruct(ok);
        for(int i=0;i<ok+1;i++){
            if(i>0) cout << " ";
            cout << ans[i];
        }
        cout << endl;
    }else if(ok < 1<<T){
        cout << ok << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 1690
memory_kb: 9084
final_rank: 11

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

vector<vector<int>> Mul(vector<vector<int>> A, vector<vector<int>> B) {
    int N = A.size();
    vector<vector<int>> Ret(N,vector<int>(N,-1));
    rep(i,0,N) Ret[i][i] = 0;
    rep(i,0,N) {
        rep(j,0,N) {
            rep(k,0,N) {
                if (A[i][j] >= 0 && B[j][k] >= 0) chmax(Ret[i][k],min(inf,A[i][j]+B[j][k]));
            }
        }
    }
    return Ret;
}

vector<vector<int>> Pow(vector<vector<int>> A, int X) {
    int N = A.size();
    if (X == 0) {
        vector<vector<int>> Ret(N,vector<int>(N,-1));
        rep(i,0,N) Ret[i][i] = 0;
        return Ret;
    }
    if (X % 2 == 0) {
        auto Ret = Pow(A,X/2);
        return Mul(Ret,Ret);
    }
    return Mul(A,Pow(A,X-1));
}

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<vector<int>> D(N,vector<int>(N,-1));
    rep(i,0,N) D[i][i] = 0;
    vector<int> U(M), V(M), C(M);
    rep(i,0,M) {
        cin >> U[i] >> V[i] >> C[i];
        chmax(D[U[i]][V[i]],C[i]);
    }
    int NG = -1, OK = 1000001;
    while(OK - NG > 1) {
        int MID = (OK + NG) / 2;
        auto Ret = Pow(D,MID);
        bool check = false;
        rep(i,0,N) {
            rep(j,0,N) {
                if (Ret[i][j] >= K) check = true;
            }
        }
        if (check) OK = MID;
        else NG = MID;
    }
    if (OK == 1000001) {
        cout << -1 << endl;
        return 0;
    }
    if (OK > 100) {
        cout << OK << endl;
        return 0;
    }
    int MAX = 0;
    vector<vector<vector<int>>> DP(OK+1);
    DP[0] = Pow(D,0);
    rep(i,0,OK) DP[i+1] = Mul(DP[i],D);
    int S, G;
    rep(i,0,N) {
        rep(j,0,N) {
            if (DP[OK][i][j] >= K) {
                if (chmax(MAX,DP[OK][i][j])) {
                    S = i, G = j;
                }
            }
        }
    }
    vector<int> ANS;
    ANS.push_back(G);
    rrep(i,0,OK) {
        rep(j,0,M) {
            if (V[j] != G) continue;
            if (min(inf,DP[i][S][U[j]] + C[j]) == DP[i+1][S][G]) {
                ANS.push_back(U[j]);
                G = U[j];
                break;
            }
        }
    }
    reverse(ALL(ANS));
    cout << OK << endl;
    rep(i,0,ANS.size()) cout << ANS[i] << (i == ANS.size()-1 ? '\n' : ' ');
}
accuracy: 1
time_ms: 2200
memory_kb: 7860
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define rep(i,n) for(ll i=0;i<ll(n);i++)

const ll mod = 1e9 + 7;

vvll mul(vvll A,vvll B){
    ll N=A.size();
    vvll R(N,vll(N,-1e18));
    rep(i,N)R[i][i]=0;
    rep(i,N)rep(j,N){
        rep(k,N)R[i][j]=max(R[i][j],A[i][k]+B[k][j]);
    }
    return R;
}

ll f(vvll A,ll n){
    ll N=A.size();
    vvll E(N,vll(N,0));
    vvll B=A;
    while(n>0){
        if(n%2)E=mul(B,E);
        vvll NB=mul(B,B);
        rep(i,N)rep(j,N)B[i][j]=max(B[i][j],NB[i][j]);
        n/=2;
    }
    ll res=0;
    rep(i,N)rep(j,N)res=max(res,E[i][j]);
    return res;
}

int main() {
    ll N,M,K;
    cin>>N>>M>>K;
    vvll A(N,vll(N,-1e18));
    rep(i,M){
        ll a,b,c;
        cin>>a>>b>>c;
        A[a][b]=max(A[a][b],c);
    }
    vector<vector<pair<ll,ll>>> DP(101,vector<pair<ll,ll>>(N,{0,-1}));
    rep(i,100){
        ll MX=-1,id=-1;
        rep(j,N)rep(k,N){
            if(DP[i+1][j].first<DP[i][k].first+A[k][j]){
                DP[i+1][j].first=DP[i][k].first+A[k][j];
                DP[i+1][j].second=k;
            }
            if(DP[i+1][j].first>MX){
                MX=DP[i+1][j].first;
                id=j;
            }
        }
        if(MX>=K){
            cout<<i+1<<endl;
            vll AN;
            AN.push_back(id);
            for(ll n=i+1;n>0;n--){
                id=DP[n][id].second;
                AN.push_back(id);
            }
            reverse(AN.begin(),AN.end());
            rep(n,i+2)cout<<AN[n]<<" \n"[n==i+1];
            return 0;
        }
    }
    ll L=10,R=1e7;
    while(R-L>1){
        ll mid=(R+L)/2;
        ll res=f(A,mid);
        (res>=K?R:L)=mid;
    }
    cout<<(R<5e6?R:-1)<<endl;
}
accuracy: 1
time_ms: 1650
memory_kb: 4724
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define rep(i,n) for(ll i=0;i<ll(n);i++)

const ll mod = 1e9 + 7;

vvll mul(vvll A,vvll B){
    ll N=A.size();
    vvll R(N,vll(N,-1e18));
    rep(i,N)rep(j,N){
        rep(k,N)R[i][j]=max(R[i][j],A[i][k]+B[k][j]);
    }
    return R;
}

int main() {
    ll N,M,K;
    cin>>N>>M>>K;
    vvll A(N,vll(N,-1e18));
    rep(i,M){
        ll a,b,c;
        cin>>a>>b>>c;
        A[a][b]=max(A[a][b],c);
    }
    vector<vector<pair<ll,ll>>> DP(101,vector<pair<ll,ll>>(N,{0,-1}));
    rep(i,100){
        ll MX=-1,id=-1;
        rep(j,N)rep(k,N){
            if(DP[i+1][j].first<DP[i][k].first+A[k][j]){
                DP[i+1][j].first=DP[i][k].first+A[k][j];
                DP[i+1][j].second=k;
            }
            if(DP[i+1][j].first>MX){
                MX=DP[i+1][j].first;
                id=j;
            }
        }
        if(MX>=K){
            cout<<i+1<<endl;
            vll AN;
            AN.push_back(id);
            for(ll n=i+1;n>0;n--){
                id=DP[n][id].second;
                AN.push_back(id);
            }
            reverse(AN.begin(),AN.end());
            rep(n,i+2)cout<<AN[n]<<" \n"[n==i+1];
            return 0;
        }
    }
    ll L=10,R=1e7;
    while(R-L>1){
        ll mid=(R+L)/2;
        vvll E(N,vll(N,0));
        ll n=mid;
        vvll B=A;
        while(n>0){
            if(n%2)E=mul(E,B);
            B=mul(B,B);
            n/=2;
        }
        bool OK=0;
        rep(i,N)rep(j,N){
            if(E[i][j]>=K)OK=1;
        }
        (OK?R:L)=mid;
    }
    cout<<(R<5e6?R:-1)<<endl;
}
accuracy: 0.8
time_ms: 1680
memory_kb: 4540
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;

template<class T>
bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0;}

template<class T>
bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}

using ll = long long;
using ld = long double;

const ll INF = 1e15;

template <class T>
struct Matrix
{
	vector<vector<T>> mat;
	
	Matrix(int r, int c, T init_value = 0) : mat(r, vector<T>(c, init_value)) { }
	
	/*--- operator ---*/
	
	int height() const
	{
		return mat.size();
	}
	
	int width() const
	{
		return mat[0].size();
	}
	
	Matrix &operator=(const Matrix &rhs)
	{
		this.mat = rhs.mat;
		return *this;
	}
	
	Matrix operator-() const
	{
		int h = height(), w = width();
		Matrix ret = *this;
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				ret.mat[i][j] = -ret.mat[i][j];
			}
		}
		return ret;
	}
	
	Matrix &operator+=(const Matrix &rhs)
	{
		int h = height(), w = width();
		assert(rhs.height() == h && rhs.width() == w);
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				this.mat[i][j] += rhs.mat[i][j];
			}
		}
		return *this;
	}
	
	Matrix &operator-=(const Matrix &rhs)
	{
		int h = height(), w = width();
		assert(rhs.height() == h && rhs.width() == w);
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				this.mat[i][j] -= rhs.mat[i][j];
			}
		}
		return *this;
	}
	
	Matrix &operator*=(const Matrix &rhs)
	{
		int h = height(), w = width();
		int hr = rhs.height(), wr = rhs.width();
		assert(w == hr);
		
		Matrix mult(h, wr, 0);
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < wr; ++j)
			{
				T ret = (*this).mat[i][j];
				for (int k = 0; k < w; ++k)
				{
					ret = max(ret, (*this).mat[i][k] + rhs.mat[k][j]); 
				}
				mult.mat[i][j] = ret;
			}
		}
		mat = mult.mat;
		return *this;
	}
	
	Matrix operator+(const Matrix &rhs) const
	{
		return (Matrix(*this) += rhs);
	}
	
	Matrix operator-(const Matrix &rhs) const
	{
		return (Matrix(*this) -= rhs);
	}
	
	Matrix operator*(const Matrix &rhs) const
	{
		return (Matrix(*this) *= rhs);
	}
	
	/*--- function ---*/
	
	Matrix pow(long long n) const
	{
		int h = height(), w = width();
		assert(h == w);
		
		Matrix ret(h, w, 0);
		// for (int i = 0; i < w; ++i) {ret.mat[i][i] = 1;}
		Matrix p2 = *this;
		
		while (n > 0)
		{
			if (n & 1) {ret *= p2;}
			p2 *= p2;
			n >>= 1;
		}
		return ret;
	}
	
	void print() const
	{
		cout << "Matrix size is " << height() << " * " << width() << "." << endl;
		for (int i = 0; i < height(); ++i)
		{
			for (int j = 0; j < width(); ++j)
			{
				cout << mat[i][j] << " ";
			}
			cout << endl;
		}
		return;
	}
	
};

bool isOK(const Matrix<ll> &mat, ll mid, ll K)
{
	ll N = mat.mat.size();
	auto p = mat.pow(mid);
	
	ll mx = -INF;
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			chmax(mx, p.mat[i][j]);
		}
	}
	
	return mx >= K;
}

// edge num, vertex := (max value, last vertex)
pair<ll, ll> dp[160][160];

void calc()
{
	ll N, M, K; cin >> N >> M >> K;
	Matrix<ll> adj(N, N, -INF);
	for (int i = 0; i < M; ++i)
	{
		ll u, v, c; cin >> u >> v >> c;
		chmax(adj.mat[u][v], c);
	}
	
	
	
	
	ll ok = 1<<20, ng = 0;
	
	if (!isOK(adj, ok, K))
	{
		cout << -1 << endl;
		return;
	}
	
	
	while (abs(ok - ng) > 1)
	{
		ll mid = (ok + ng) / 2;
		if (isOK(adj, mid, K)) ok = mid;
		else ng = mid;
	}
	
	cout << ok << endl;
	
	if (ok <= 100)
	{
		for (int c = 0; c < 160; ++c)
		{
			for (int v = 0; v < 160; ++v)
			{
				dp[c][v] = make_pair(-INF, -1);
			}
		}
		
		for (int v = 0; v < N; ++v)
		{
			dp[0][v] = make_pair(0, -1);
		}
		
		bool flg = false;
		for (ll c = 1; c < 160; ++c)
		{
			for (ll v = 0; v < N; ++v)
			{
				for (ll pv = 0; pv < N; ++pv)
				{
					auto [d, h] = dp[c-1][pv];
					ll cost = adj.mat[pv][v];
					
					chmax(dp[c][v], make_pair(d+cost, pv));
				}
				// cout << c << " " << v << " " << dp[c][v].first << " " << dp[c][v].second << endl;
			}
		}
		
		ll t = -1, mx = -INF;
		for (int v = 0; v < N; ++v)
		{
			if (chmax(mx, dp[ok][v].first)) t = v;
		}
		assert(t != -1);
		
		vector<ll> res;
		ll now = t, cnt = ok;
		while (cnt >= 0)
		{
			res.emplace_back(now);
			
			auto [d, pv] = dp[cnt][now];
			now = pv;
			cnt--;
		}
		
		reverse(res.begin(), res.end());
		assert(res.size() == ok+1);
		
		for (auto v : res)
		{
			cout << v << " ";
		}
		cout << endl;
	}
	
	// auto p = adj.pow(992400);
	// ll mx = 0;
	// for (int i = 0; i < N; ++i)
	// {
	// 	for (int j = 0; j < N; ++j)
	// 	{
	// 		chmax(mx, p.mat[i][j]);
	// 	}
	// }
	// cout << mx << endl;
	
	return;
}

int main()
{
	calc();
	
	return 0;
}
accuracy: 1
time_ms: 950
memory_kb: 4080
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;

template<class T>
bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0;}

template<class T>
bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}

using ll = long long;
using ld = long double;

const ll INF = 1e15;

template <class T>
struct Matrix
{
	vector<vector<T>> mat;
	
	Matrix(int r, int c, T init_value = 0) : mat(r, vector<T>(c, init_value)) { }
	
	/*--- operator ---*/
	
	int height() const
	{
		return mat.size();
	}
	
	int width() const
	{
		return mat[0].size();
	}
	
	Matrix &operator=(const Matrix &rhs)
	{
		this.mat = rhs.mat;
		return *this;
	}
	
	Matrix operator-() const
	{
		int h = height(), w = width();
		Matrix ret = *this;
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				ret.mat[i][j] = -ret.mat[i][j];
			}
		}
		return ret;
	}
	
	Matrix &operator+=(const Matrix &rhs)
	{
		int h = height(), w = width();
		assert(rhs.height() == h && rhs.width() == w);
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				this.mat[i][j] += rhs.mat[i][j];
			}
		}
		return *this;
	}
	
	Matrix &operator-=(const Matrix &rhs)
	{
		int h = height(), w = width();
		assert(rhs.height() == h && rhs.width() == w);
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				this.mat[i][j] -= rhs.mat[i][j];
			}
		}
		return *this;
	}
	
	Matrix &operator*=(const Matrix &rhs)
	{
		int h = height(), w = width();
		int hr = rhs.height(), wr = rhs.width();
		assert(w == hr);
		
		Matrix mult(h, wr, 0);
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < wr; ++j)
			{
				T ret = (*this).mat[i][j];
				for (int k = 0; k < w; ++k)
				{
					ret = max(ret, (*this).mat[i][k] + rhs.mat[k][j]); 
				}
				mult.mat[i][j] = ret;
			}
		}
		mat = mult.mat;
		return *this;
	}
	
	Matrix operator+(const Matrix &rhs) const
	{
		return (Matrix(*this) += rhs);
	}
	
	Matrix operator-(const Matrix &rhs) const
	{
		return (Matrix(*this) -= rhs);
	}
	
	Matrix operator*(const Matrix &rhs) const
	{
		return (Matrix(*this) *= rhs);
	}
	
	/*--- function ---*/
	
	Matrix pow(long long n) const
	{
		int h = height(), w = width();
		assert(h == w);
		
		Matrix ret(h, w, 0);
		// for (int i = 0; i < w; ++i) {ret.mat[i][i] = 1;}
		Matrix p2 = *this;
		
		while (n > 0)
		{
			if (n & 1) {ret *= p2;}
			p2 *= p2;
			n >>= 1;
		}
		return ret;
	}
	
	void print() const
	{
		cout << "Matrix size is " << height() << " * " << width() << "." << endl;
		for (int i = 0; i < height(); ++i)
		{
			for (int j = 0; j < width(); ++j)
			{
				cout << mat[i][j] << " ";
			}
			cout << endl;
		}
		return;
	}
	
};

bool isOK(const Matrix<ll> &mat, ll mid, ll K)
{
	ll N = mat.mat.size();
	auto p = mat.pow(mid);
	
	ll mx = -INF;
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			chmax(mx, p.mat[i][j]);
		}
	}
	
	return mx >= K;
}

// edge num, vertex := (max value, last vertex)
pair<ll, ll> dp[160][160];

void calc()
{
	ll N, M, K; cin >> N >> M >> K;
	Matrix<ll> adj(N, N, -INF);
	for (int i = 0; i < M; ++i)
	{
		ll u, v, c; cin >> u >> v >> c;
		chmax(adj.mat[u][v], c);
	}
	
	{
		for (int c = 0; c < 160; ++c)
		{
			for (int v = 0; v < 160; ++v)
			{
				dp[c][v] = make_pair(-INF, -1);
			}
		}
		
		for (int v = 0; v < N; ++v)
		{
			dp[0][v] = make_pair(0, -1);
		}
		
		bool flg = false;
		ll ok = INF;
		for (ll c = 1; c < 160; ++c)
		{
			for (ll v = 0; v < N; ++v)
			{
				for (ll pv = 0; pv < N; ++pv)
				{
					auto [d, h] = dp[c-1][pv];
					ll cost = adj.mat[pv][v];
					
					chmax(dp[c][v], make_pair(d+cost, pv));
				}
				if (dp[c][v].first >= K) flg = true;
				// cout << c << " " << v << " " << dp[c][v].first << " " << dp[c][v].second << endl;
			}
			if (flg)
			{
				chmin(ok, c);
			}
		}
		
		if (flg)
		{
			ll t = -1, mx = -INF;
			for (int v = 0; v < N; ++v)
			{
				if (chmax(mx, dp[ok][v].first)) t = v;
			}
			assert(t != -1);
			
			vector<ll> res;
			ll now = t, cnt = ok;
			while (cnt >= 0)
			{
				res.emplace_back(now);
				
				auto [d, pv] = dp[cnt][now];
				now = pv;
				cnt--;
			}
			
			reverse(res.begin(), res.end());
			assert(res.size() == ok+1);
			
			cout << ok << endl;
			if (ok <= 100)
			{
				for (auto v : res)
				{
					cout << v << " ";
				}
				cout << endl;
			}
			
			return;
		}
		
		{
			ll mx = -INF;
			for (int i = 0; i < N; ++i)
			{
				chmax(mx, dp[159][i].first);
			}
			
			if (mx < 0)
			{
				cout << -1 << endl;
				return;
			}
		}
	}
	
	
	ll ok = 1<<20, ng = 0;
	
	while (abs(ok - ng) > 1)
	{
		ll mid = (ok + ng) / 2;
		if (isOK(adj, mid, K)) ok = mid;
		else ng = mid;
	}
	
	cout << ok << endl;
	
	// auto p = adj.pow(992400);
	// ll mx = 0;
	// for (int i = 0; i < N; ++i)
	// {
	// 	for (int j = 0; j < N; ++j)
	// 	{
	// 		chmax(mx, p.mat[i][j]);
	// 	}
	// }
	// cout << mx << endl;
	
	return;
}

int main()
{
	calc();
	
	return 0;
}
accuracy: 1
time_ms: 900
memory_kb: 4372
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;

template<class T>
bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0;}

template<class T>
bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}

using ll = long long;
using ld = long double;

const ll INF = 1e9;

template <class T>
struct Matrix
{
	vector<vector<T>> mat;
	
	Matrix(int r, int c, T init_value = 0) : mat(r, vector<T>(c, init_value)) { }
	
	/*--- operator ---*/
	
	int height() const
	{
		return mat.size();
	}
	
	int width() const
	{
		return mat[0].size();
	}
	
	Matrix &operator=(const Matrix &rhs)
	{
		this.mat = rhs.mat;
		return *this;
	}
	
	Matrix operator-() const
	{
		int h = height(), w = width();
		Matrix ret = *this;
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				ret.mat[i][j] = -ret.mat[i][j];
			}
		}
		return ret;
	}
	
	Matrix &operator+=(const Matrix &rhs)
	{
		int h = height(), w = width();
		assert(rhs.height() == h && rhs.width() == w);
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				this.mat[i][j] += rhs.mat[i][j];
			}
		}
		return *this;
	}
	
	Matrix &operator-=(const Matrix &rhs)
	{
		int h = height(), w = width();
		assert(rhs.height() == h && rhs.width() == w);
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				this.mat[i][j] -= rhs.mat[i][j];
			}
		}
		return *this;
	}
	
	Matrix &operator*=(const Matrix &rhs)
	{
		int h = height(), w = width();
		int hr = rhs.height(), wr = rhs.width();
		assert(w == hr);
		
		Matrix mult(h, wr, 0);
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < wr; ++j)
			{
				T ret = -INF;
				for (int k = 0; k < w; ++k)
				{
					ret = max(ret, (*this).mat[i][k] + rhs.mat[k][j]); 
				}
				mult.mat[i][j] = ret;
			}
		}
		mat = mult.mat;
		return *this;
	}
	
	Matrix operator+(const Matrix &rhs) const
	{
		return (Matrix(*this) += rhs);
	}
	
	Matrix operator-(const Matrix &rhs) const
	{
		return (Matrix(*this) -= rhs);
	}
	
	Matrix operator*(const Matrix &rhs) const
	{
		return (Matrix(*this) *= rhs);
	}
	
	/*--- function ---*/
	
	Matrix pow(long long n) const
	{
		int h = height(), w = width();
		assert(h == w);
		
		Matrix ret(h, w, 0);
		// for (int i = 0; i < w; ++i) {ret.mat[i][i] = 1;}
		Matrix p2 = *this;
		
		while (n > 0)
		{
			if (n & 1) {ret *= p2;}
			p2 *= p2;
			n >>= 1;
		}
		return ret;
	}
	
	void print() const
	{
		cout << "Matrix size is " << height() << " * " << width() << "." << endl;
		for (int i = 0; i < height(); ++i)
		{
			for (int j = 0; j < width(); ++j)
			{
				cout << mat[i][j] << " ";
			}
			cout << endl;
		}
		return;
	}
	
};

bool isOK(const Matrix<ll> &mat, ll mid, ll K)
{
	ll N = mat.mat.size();
	auto p = mat.pow(mid);
	
	ll mx = -INF;
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			chmax(mx, p.mat[i][j]);
		}
	}
	
	return mx >= K;
}

// edge num, vertex := (max value, last vertex)
pair<ll, ll> dp[160][160];

void calc()
{
	ll N, M, K; cin >> N >> M >> K;
	Matrix<ll> adj(N, N, -INF);
	for (int i = 0; i < M; ++i)
	{
		ll u, v, c; cin >> u >> v >> c;
		chmax(adj.mat[u][v], c);
	}
	
	{
		for (int c = 0; c < 160; ++c)
		{
			for (int v = 0; v < 160; ++v)
			{
				dp[c][v] = make_pair(-INF, -1);
			}
		}
		
		for (int v = 0; v < N; ++v)
		{
			dp[0][v] = make_pair(0, -1);
		}
		
		bool flg = false;
		ll ok = INF;
		for (ll c = 1; c < 160; ++c)
		{
			for (ll v = 0; v < N; ++v)
			{
				for (ll pv = 0; pv < N; ++pv)
				{
					auto [d, h] = dp[c-1][pv];
					ll cost = adj.mat[pv][v];
					
					chmax(dp[c][v], make_pair(d+cost, pv));
				}
				if (dp[c][v].first >= K) flg = true;
				// cout << c << " " << v << " " << dp[c][v].first << " " << dp[c][v].second << endl;
			}
			if (flg)
			{
				chmin(ok, c);
			}
		}
		
		if (flg)
		{
			ll t = -1, mx = -INF;
			for (int v = 0; v < N; ++v)
			{
				if (chmax(mx, dp[ok][v].first)) t = v;
			}
			assert(t != -1);
			
			vector<ll> res;
			ll now = t, cnt = ok;
			while (cnt >= 0)
			{
				res.emplace_back(now);
				
				auto [d, pv] = dp[cnt][now];
				now = pv;
				cnt--;
			}
			
			reverse(res.begin(), res.end());
			assert(res.size() == ok+1);
			
			cout << ok << endl;
			if (ok <= 100)
			{
				for (auto v : res)
				{
					cout << v << " ";
				}
				cout << endl;
			}
			
			return;
		}
		
		{
			ll mx = -INF;
			for (int i = 0; i < N; ++i)
			{
				chmax(mx, dp[159][i].first);
			}
			
			if (mx < 0)
			{
				cout << -1 << endl;
				return;
			}
		}
	}
	
	
	ll ok = 2*K, ng = 0;
	
	while (abs(ok - ng) > 1)
	{
		ll mid = (ok + ng) / 2;
		if (isOK(adj, mid, K)) ok = mid;
		else ng = mid;
	}
	
	cout << ok << endl;
	
	return;
}

int main()
{
	calc();
	
	return 0;
}
accuracy: 0.8
time_ms: 1120
memory_kb: 4304
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

template<class T>
bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0;}

template<class T>
bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}

using ll = long long;
using ld = long double;

const ll INF = 1e9;

template <class T>
struct Matrix
{
	vector<vector<T>> mat;
	
	Matrix(int r, int c, T init_value = 0) : mat(r, vector<T>(c, init_value)) { }
	
	/*--- operator ---*/
	
	int height() const
	{
		return mat.size();
	}
	
	int width() const
	{
		return mat[0].size();
	}
	
	Matrix &operator=(const Matrix &rhs)
	{
		this.mat = rhs.mat;
		return *this;
	}
	
	Matrix operator-() const
	{
		int h = height(), w = width();
		Matrix ret = *this;
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				ret.mat[i][j] = -ret.mat[i][j];
			}
		}
		return ret;
	}
	
	Matrix &operator+=(const Matrix &rhs)
	{
		int h = height(), w = width();
		assert(rhs.height() == h && rhs.width() == w);
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				this.mat[i][j] += rhs.mat[i][j];
			}
		}
		return *this;
	}
	
	Matrix &operator-=(const Matrix &rhs)
	{
		int h = height(), w = width();
		assert(rhs.height() == h && rhs.width() == w);
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				this.mat[i][j] -= rhs.mat[i][j];
			}
		}
		return *this;
	}
	
	Matrix &operator*=(const Matrix &rhs)
	{
		int h = height(), w = width();
		int hr = rhs.height(), wr = rhs.width();
		assert(w == hr);
		
		Matrix mult(h, wr, 0);
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < wr; ++j)
			{
				T ret = -INF;
				for (int k = 0; k < w; ++k)
				{
					ret = max(ret, (*this).mat[i][k] + rhs.mat[k][j]); 
				}
				mult.mat[i][j] = ret;
			}
		}
		mat = mult.mat;
		return *this;
	}
	
	Matrix operator+(const Matrix &rhs) const
	{
		return (Matrix(*this) += rhs);
	}
	
	Matrix operator-(const Matrix &rhs) const
	{
		return (Matrix(*this) -= rhs);
	}
	
	Matrix operator*(const Matrix &rhs) const
	{
		return (Matrix(*this) *= rhs);
	}
	
	/*--- function ---*/
	
	Matrix pow(long long n) const
	{
		int h = height(), w = width();
		assert(h == w);
		
		Matrix ret(h, w, 0);
		// for (int i = 0; i < w; ++i) {ret.mat[i][i] = 1;}
		Matrix p2 = *this;
		
		while (n > 0)
		{
			if (n & 1) {ret *= p2;}
			p2 *= p2;
			n >>= 1;
		}
		return ret;
	}
	
	void print() const
	{
		cout << "Matrix size is " << height() << " * " << width() << "." << endl;
		for (int i = 0; i < height(); ++i)
		{
			for (int j = 0; j < width(); ++j)
			{
				cout << mat[i][j] << " ";
			}
			cout << endl;
		}
		return;
	}
	
};

bool isOK(const Matrix<ll> &mat, ll mid, ll K)
{
	ll N = mat.mat.size();
	auto p = mat.pow(mid);
	
	ll mx = -INF;
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			chmax(mx, p.mat[i][j]);
		}
	}
	
	return mx >= K;
}

// edge num, vertex := (max value, last vertex)
pair<ll, ll> dp[110][110];

void calc()
{
	ll N, M, K; cin >> N >> M >> K;
	Matrix<ll> adj(N, N, -INF);
	for (int i = 0; i < M; ++i)
	{
		ll u, v, c; cin >> u >> v >> c;
		chmax(adj.mat[u][v], c);
	}
	
	ll ok = 2*K, ng = 0;
	
	if (!isOK(adj, ok, K))
	{
		cout << -1 << endl;
		return;
	}
	
	while (abs(ok - ng) > 1)
	{
		ll mid = (ok + ng) / 2;
		if (isOK(adj, mid, K)) ok = mid;
		else ng = mid;
	}
	
	cout << ok << endl;
	
	if (ok <= 100)
	{
		for (int c = 0; c < 110; ++c)
		{
			for (int v = 0; v < 110; ++v)
			{
				dp[c][v] = make_pair(-INF, -1);
			}
		}
		
		for (int v = 0; v < N; ++v)
		{
			dp[0][v] = make_pair(0, -1);
		}
		
		for (ll c = 1; c <= ok; ++c)
		{
			for (ll v = 0; v < N; ++v)
			{
				for (ll pv = 0; pv < N; ++pv)
				{
					auto [d, h] = dp[c-1][pv];
					ll cost = adj.mat[pv][v];
					
					chmax(dp[c][v], make_pair(d+cost, pv));
				}
				// cout << c << " " << v << " " << dp[c][v].first << " " << dp[c][v].second << endl;
			}
		}
		
		ll t = -1, mx = -INF;
		for (int v = 0; v < N; ++v)
		{
			if (chmax(mx, dp[ok][v].first)) t = v;
		}
		assert(t != -1);
		
		vector<ll> res;
		ll now = t, cnt = ok;
		while (cnt >= 0)
		{
			res.emplace_back(now);
			
			auto [d, pv] = dp[cnt][now];
			now = pv;
			cnt--;
		}
		
		reverse(res.begin(), res.end());
		
		assert(res.size() == ok+1);
		for (auto v : res)
		{
			cout << v << " ";
		}
		cout << endl;
		
	}
	
	
	return;
}

int main()
{
	calc();
	
	return 0;
}
accuracy: 0.7333333333333333
time_ms: 1170
memory_kb: 3892
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
	// step #1. input
	int V, E, K;
	cin >> V >> E >> K;
	const int INF = 1012345678;
	vector<vector<int> > d(V, vector<int>(V, -INF));
	for (int i = 0; i < E; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		d[a][b] = max(d[a][b], c);
	}

	// step #2. first dp
	const int limit = 100;
	vector<vector<int> > dp1(limit + 1, vector<int>(V, -INF));
	vector<vector<int> > pre(limit + 1, vector<int>(V, -1));
	dp1[0] = vector<int>(V, 0);
	for (int i = 1; i <= limit; i++) {
		for (int j = 0; j < V; j++) {
			for (int k = 0; k < V; k++) {
				if (d[k][j] != -INF && dp1[i][j] < dp1[i - 1][k] + d[k][j]) {
					dp1[i][j] = dp1[i - 1][k] + d[k][j];
					pre[i][j] = k;
				}
			}
		}
	}
	bool found = false;
	for (int i = 0; i <= limit && !found; i++) {
		int pos = max_element(dp1[i].begin(), dp1[i].end()) - dp1[i].begin();
		if (dp1[i][pos] >= K) {
			found = true;
			vector<int> v(i + 1);
			v[i] = pos;
			for (int j = i - 1; j >= 0; j--) {
				v[j] = pre[j + 1][v[j + 1]];
			}
			cout << i << endl;
			for (int j = 0; j <= i; j++) {
				if (j != 0) {
					cout << ' ';
				}
				cout << v[j];
			}
			cout << endl;
		}
	}

	// step #3. second dp
	if (!found) {
		const int bits = 32 - __builtin_clz(K + 1);
		vector<vector<vector<int> > > dp2(bits);
		dp2[0] = d;
		for (int i = 1; i < bits; i++) {
			dp2[i] = dp2[i - 1];
			for (int j = 0; j < V; j++) {
				for (int k = 0; k < V; k++) {
					for (int l = 0; l < V; l++) {
						if (dp2[i - 1][j][l] != -INF && dp2[i - 1][l][k] != -INF) {
							dp2[i][j][k] = max(dp2[i][j][k], dp2[i - 1][j][l] + dp2[i - 1][l][k]);
						}
					}
				}
			}
		}
		vector<vector<int> > dp3(V, vector<int>(V, -INF));
		for (int i = 0; i < V; i++) {
			dp3[i][i] = 0;
		}
		int ans = 0;
		for (int i = bits - 1; i >= 0; i--) {
			vector<vector<int> > dp4(V, vector<int>(V, -INF));
			for (int j = 0; j < V; j++) {
				for (int k = 0; k < V; k++) {
					for (int l = 0; l < V; l++) {
						if (dp3[j][l] != -INF && dp2[i][l][k] != -INF) {
							dp4[j][k] = max(dp4[j][k], dp3[j][l] + dp2[i][l][k]);
						}
					}
				}
			}
			bool flag = false;
			for (int j = 0; j < V; j++) {
				for (int k = 0; k < V; k++) {
					if (dp4[j][k] >= K) {
						flag = true;
					}
				}
			}
			if (!flag) {
				dp3 = dp4;
				ans += (1 << i);
			}
		}
		ans += 1;
		if (ans == (1 << bits)) {
			cout << -1 << endl;
		}
		else {
			cout << ans << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 5672
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
	// step #1. input
	int V, E, K;
	cin >> V >> E >> K;
	const int INF = 1012345678;
	vector<vector<int> > d(V, vector<int>(V, -INF));
	for (int i = 0; i < E; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		d[a][b] = max(d[a][b], c);
	}

	// step #2. first dp
	const int limit = 100;
	vector<vector<int> > dp1(limit + 1, vector<int>(V, -INF));
	vector<vector<int> > pre(limit + 1, vector<int>(V, -1));
	dp1[0] = vector<int>(V, 0);
	for (int i = 1; i <= limit; i++) {
		for (int j = 0; j < V; j++) {
			for (int k = 0; k < V; k++) {
				if (d[k][j] != -INF && dp1[i][j] < dp1[i - 1][k] + d[k][j]) {
					dp1[i][j] = dp1[i - 1][k] + d[k][j];
					pre[i][j] = k;
				}
			}
		}
	}
	bool found = false;
	for (int i = 0; i <= limit && !found; i++) {
		int pos = max_element(dp1[i].begin(), dp1[i].end()) - dp1[i].begin();
		if (dp1[i][pos] >= K) {
			found = true;
			vector<int> v(i + 1);
			v[i] = pos;
			for (int j = i - 1; j >= 0; j--) {
				v[j] = pre[j + 1][v[j + 1]];
			}
			cout << i << endl;
			for (int j = 0; j <= i; j++) {
				if (j != 0) {
					cout << ' ';
				}
				cout << v[j];
			}
			cout << endl;
		}
	}

	// step #3. second dp
	if (!found) {
		const int bits = 32 - __builtin_clz(K + 1);
		vector<vector<vector<int> > > dp2(bits, vector<vector<int> >(V, vector<int>(V, -INF)));
		dp2[0] = d;
		for (int i = 1; i < bits; i++) {
			for (int j = 0; j < V; j++) {
				for (int k = 0; k < V; k++) {
					for (int l = 0; l < V; l++) {
						if (dp2[i - 1][j][l] != -INF && dp2[i - 1][l][k] != -INF) {
							dp2[i][j][k] = max(dp2[i][j][k], dp2[i - 1][j][l] + dp2[i - 1][l][k]);
						}
					}
				}
			}
		}
		vector<vector<int> > dp3(V, vector<int>(V, -INF));
		for (int i = 0; i < V; i++) {
			dp3[i][i] = 0;
		}
		int ans = 0;
		for (int i = bits - 1; i >= 0; i--) {
			vector<vector<int> > dp4(V, vector<int>(V, -INF));
			for (int j = 0; j < V; j++) {
				for (int k = 0; k < V; k++) {
					for (int l = 0; l < V; l++) {
						if (dp3[j][l] != -INF && dp2[i][l][k] != -INF) {
							dp4[j][k] = max(dp4[j][k], dp3[j][l] + dp2[i][l][k]);
						}
					}
				}
			}
			bool flag = false;
			for (int j = 0; j < V; j++) {
				for (int k = 0; k < V; k++) {
					if (dp4[j][k] >= K) {
						flag = true;
					}
				}
			}
			if (!flag) {
				dp3 = dp4;
				ans += (1 << i);
			}
		}
		ans += 1;
		if (ans == (1 << bits)) {
			cout << -1 << endl;
		}
		else {
			cout << ans << endl;
		}
	}
	return 0;
}
accuracy: 0.8
time_ms: 220
memory_kb: 5708
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define for_rev(i, a, b) for (int i = (a); i >= (b); --i)
typedef vector<int> Ary;
typedef vector<Ary> Mat;
struct Edge {
  int to, c;
};
void maxUpdate(int &a, int b) { a = max(a, b); }
void mul(Mat &res, Mat &a, Mat &b) {
  int N = a.size();
  res = a;
  for_(i, 0, N) for_(j, 0, N) for_(k, 0, N) {
    if (a[i][k] >= 0 && b[k][j] >= 0)
      maxUpdate(res[i][j], a[i][k] + b[k][j]);
  }
}
int V, K, E, dp[155][155], prv[155][155];
vector<vector<Edge>> adj;
void restore(int step, int v) {
  int c = step;
  vector<int> path;
  while (v != -1) {
    path.push_back(v);
    v = prv[c--][v];
  }
  reverse(path.begin(), path.end());
  for_(i, 0, step + 1) cout << path[i] << (i < step ? " " : "\n");
}
bool shortPhase() {
  memset(dp, -1, sizeof(dp));
  memset(prv, -1, sizeof(prv));
  for_(v, 0, V) dp[0][v] = 0;
  int max_score = -1, step = -1, terminal = -1;
  for_(i, 0, 150) {
    for_(v, 0, V) {
      if (dp[i][v] == -1)
        continue;
      for (Edge e : adj[v]) {
        if (dp[i + 1][e.to] < dp[i][v] + e.c) {
          dp[i + 1][e.to] = dp[i][v] + e.c;
          prv[i + 1][e.to] = v;
          if (max_score < dp[i + 1][e.to]) {
            max_score = dp[i + 1][e.to];
            terminal = e.to;
          }
        }
      }
    }
    if (max_score >= K) {
      step = i + 1;
      break;
    }
  }
  if (max_score >= K) {
    cout << step << endl;
    restore(step, terminal);
    return true;
  }
  if (max_score == -1) {
    cout << -1 << endl;
    return true;
  }
  return false;
}
int calcMinStep() {
  Mat mat[21], ini(V, Ary(V, -1));
  for_(v, 0, V) for (Edge e : adj[v]) { maxUpdate(ini[v][e.to], e.c); }
  mat[0] = ini;
  for_(i, 0, 20) mul(mat[i + 1], mat[i], mat[i]);
  int res = 0;
  Mat x(V, Ary(V, -1)), nx;
  for_(v, 0, V) x[v][v] = 0;
  for_rev(h, 19, 0) {
    mul(nx, x, mat[h]);
    int max_score = 0;
    for_(u, 0, V) for_(v, 0, V) maxUpdate(max_score, nx[u][v]);
    if (max_score < K) {
      x = nx;
      res += 1 << h;
    }
  }
  return res + 1;
}
void solve() {
  if (!shortPhase()) {
    int ans = calcMinStep();
    cout << (ans > (int)1e6 ? -1 : ans) << endl;
  }
}
int main() {
  cin >> V >> E >> K;
  adj.assign(V, vector<Edge>());
  for_(i, 0, E) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u].push_back(Edge{v, c});
  }
  solve();
}
accuracy: 1
time_ms: 200
memory_kb: 6088
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define for_rev(i, a, b) for (int i = (a); i >= (b); --i)
typedef vector<int> Ary;
typedef vector<Ary> Mat;
struct Edge {
  int to, c;
};
void maxUpdate(int &a, int b) { a = max(a, b); }
void mul(Mat &res, Mat &a, Mat &b) {
  int N = a.size();
  res = a;
  for_(i, 0, N) for_(j, 0, N) for_(k, 0, N) {
    if (a[i][k] >= 0 && b[k][j] >= 0)
      maxUpdate(res[i][j], a[i][k] + b[k][j]);
  }
}
int V, K, E, dp[110][155], prv[110][155];
vector<vector<Edge>> adj;
void restore(int step, int v) {
  int c = step;
  vector<int> path;
  while (v != -1) {
    path.push_back(v);
    v = prv[c--][v];
  }
  reverse(path.begin(), path.end());
  for_(i, 0, step + 1) cout << path[i] << (i < step ? " " : "\n");
}
bool shortPhase() {
  memset(dp, -1, sizeof(dp));
  memset(prv, -1, sizeof(prv));
  for_(v, 0, V) dp[0][v] = 0;
  int max_score = -1, step = -1, terminal = -1;
  for_(i, 0, 100) {
    for_(v, 0, V) {
      if (dp[i][v] == -1)
        continue;
      for (Edge e : adj[v]) {
        if (dp[i + 1][e.to] < dp[i][v] + e.c) {
          dp[i + 1][e.to] = dp[i][v] + e.c;
          prv[i + 1][e.to] = v;
          if (max_score < dp[i + 1][e.to]) {
            max_score = dp[i + 1][e.to];
            terminal = e.to;
          }
        }
      }
    }
    if (max_score >= K) {
      step = i + 1;
      break;
    }
  }
  if (max_score >= K) {
    cout << step << endl;
    restore(step, terminal);
    return true;
  }
  return false;
}
int calcMinStep() {
  Mat mat[20], ini(V, Ary(V, -1));
  for_(v, 0, V) for (Edge e : adj[v]) { maxUpdate(ini[v][e.to], e.c); }
  mat[0] = ini;
  for_(i, 0, 19) mul(mat[i + 1], mat[i], mat[i]);
  int res = 0;
  Mat x(V, Ary(V, -1)), nx;
  for_(v, 0, V) x[v][v] = 0;
  for_rev(h, 19, 0) {
    mul(nx, x, mat[h]);
    int max_score = 0;
    for_(u, 0, V) for_(v, 0, V) maxUpdate(max_score, nx[u][v]);
    if (max_score < K) {
      x = nx;
      res += 1 << h;
    }
  }
  return res + 1;
}
void solve() {
  if (!shortPhase()) {
    int ans = calcMinStep();
    cout << (ans > (int)1e6 ? -1 : ans) << endl;
  }
}
int main() {
  cin >> V >> E >> K;
  adj.assign(V, vector<Edge>());
  for_(i, 0, E) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u].push_back(Edge{v, c});
  }
  solve();
}
accuracy: 1
time_ms: 190
memory_kb: 5856
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define for_rev(i, a, b) for (int i = (a); i >= (b); --i)
typedef vector<int> Ary;
typedef vector<Ary> Mat;
struct Edge {
  int to, c;
};
void maxUpdate(int &a, int b) { a = max(a, b); }
void mul(Mat &res, Mat &a, Mat &b) {
  int N = a.size();
  res = a;
  for_(i, 0, N) for_(j, 0, N) for_(k, 0, N) {
    if (a[i][k] >= 0 && b[k][j] >= 0)
      maxUpdate(res[i][j], a[i][k] + b[k][j]);
  }
}
int V, K, E, dp[155][155], prv[155][155];
vector<vector<Edge>> adj;
void restore(int step, int v) {
  int c = step;
  vector<int> path;
  while (v != -1) {
    path.push_back(v);
    v = prv[c--][v];
  }
  reverse(path.begin(), path.end());
  for_(i, 0, step + 1) cout << path[i] << (i < step ? " " : "\n");
}
bool shortPhase() {
  memset(dp, -1, sizeof(dp));
  memset(prv, -1, sizeof(prv));
  for_(v, 0, V) dp[0][v] = 0;
  int max_score = -1, step = -1, terminal = -1;
  for_(i, 0, 50) {
    for_(v, 0, V) {
      if (dp[i][v] == -1)
        continue;
      for (Edge e : adj[v]) {
        if (dp[i + 1][e.to] < dp[i][v] + e.c) {
          dp[i + 1][e.to] = dp[i][v] + e.c;
          prv[i + 1][e.to] = v;
          if (max_score < dp[i + 1][e.to]) {
            max_score = dp[i + 1][e.to];
            terminal = e.to;
          }
        }
      }
    }
    if (max_score >= K) {
      step = i + 1;
      break;
    }
  }
  if (max_score >= K) {
    cout << step << endl;
    restore(step, terminal);
    return true;
  }
  if (max_score == -1) {
    cout << -1 << endl;
    return true;
  }
  return false;
}
int calcMinStep() {
  Mat mat[21], ini(V, Ary(V, -1));
  for_(v, 0, V) for (Edge e : adj[v]) { maxUpdate(ini[v][e.to], e.c); }
  mat[0] = ini;
  for_(i, 0, 20) mul(mat[i + 1], mat[i], mat[i]);
  int res = 0;
  Mat x(V, Ary(V, -1)), nx;
  for_(v, 0, V) x[v][v] = 0;
  for_rev(h, 19, 0) {
    mul(nx, x, mat[h]);
    int max_score = 0;
    for_(u, 0, V) for_(v, 0, V) maxUpdate(max_score, nx[u][v]);
    if (max_score < K) {
      x = nx;
      res += 1 << h;
    }
  }
  return res + 1;
}
void solve() {
  if (!shortPhase()) {
    int ans = calcMinStep();
    cout << (ans > (int)1e6 ? -1 : ans) << endl;
  }
}
int main() {
  cin >> V >> E >> K;
  adj.assign(V, vector<Edge>());
  for_(i, 0, E) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u].push_back(Edge{v, c});
  }
  solve();
}
accuracy: 0.3333333333333333
time_ms: 160
memory_kb: 5800
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define for_rev(i, a, b) for (int i = (a); i >= (b); --i)
typedef vector<int> Ary;
typedef vector<Ary> Mat;
struct Edge {
  int to, c;
};
void maxUpdate(int &a, int b) { a = max(a, b); }
void mul(Mat &res, Mat &a, Mat &b) {
  int N = a.size();
  res = a;
  for_(i, 0, N) for_(j, 0, N) for_(k, 0, N) {
    if (a[i][k] >= 0 && b[k][j] >= 0)
      maxUpdate(res[i][j], a[i][k] + b[k][j]);
  }
}
int V, K, E, dp[155][155], prv[155][155];
vector<vector<Edge>> adj;
void restore(int step, int v) {
  int c = step;
  vector<int> path;
  while (v != -1) {
    path.push_back(v);
    v = prv[c--][v];
  }
  reverse(path.begin(), path.end());
  for_(i, 0, step + 1) cout << path[i] << (i < step ? " " : "\n");
}
bool shortPhase() {
  memset(dp, -1, sizeof(dp));
  memset(prv, -1, sizeof(prv));
  for_(v, 0, V) dp[0][v] = 0;
  int max_score = -1, step = -1, terminal = -1;
  for_(i, 0, 130) {
    for_(v, 0, V) {
      if (dp[i][v] == -1)
        continue;
      for (Edge e : adj[v]) {
        if (dp[i + 1][e.to] < dp[i][v] + e.c) {
          dp[i + 1][e.to] = dp[i][v] + e.c;
          prv[i + 1][e.to] = v;
          if (max_score < dp[i + 1][e.to]) {
            max_score = dp[i + 1][e.to];
            terminal = e.to;
          }
        }
      }
    }
    if (max_score >= K) {
      step = i + 1;
      break;
    }
  }
  if (max_score >= K) {
    cout << step << endl;
    restore(step, terminal);
    return true;
  }
  if (max_score == -1) {
    cout << -1 << endl;
    return true;
  }
  return false;
}
int calcMinStep() {
  Mat mat[21], ini(V, Ary(V, -1));
  for_(v, 0, V) for (Edge e : adj[v]) { maxUpdate(ini[v][e.to], e.c); }
  mat[0] = ini;
  for_(i, 0, 20) mul(mat[i + 1], mat[i], mat[i]);
  int res = 0;
  Mat x(V, Ary(V, -1)), nx;
  for_(v, 0, V) x[v][v] = 0;
  for_rev(h, 19, 0) {
    mul(nx, x, mat[h]);
    int max_score = 0;
    for_(u, 0, V) for_(v, 0, V) maxUpdate(max_score, nx[u][v]);
    if (max_score < K) {
      x = nx;
      res += 1 << h;
    }
  }
  return res + 1;
}
void solve() {
  if (!shortPhase()) {
    int ans = calcMinStep();
    cout << (ans > (int)1e6 ? -1 : ans) << endl;
  }
}
int main() {
  cin >> V >> E >> K;
  adj.assign(V, vector<Edge>());
  for_(i, 0, E) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u].push_back(Edge{v, c});
  }
  solve();
}
accuracy: 1
time_ms: 200
memory_kb: 5928
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define for_rev(i, a, b) for (int i = (a); i >= (b); --i)
typedef vector<int> Ary;
typedef vector<Ary> Mat;
struct Edge {
  int to, c;
};
inline void maxUpdate(int &a, int b) { a = max(a, b); }
inline void mul(Mat &res, Mat &a, Mat &b) {
  int N = a.size();
  res = a;
  for_(i, 0, N) for_(j, 0, N) for_(k, 0, N) {
    if (a[i][k] >= 0 && b[k][j] >= 0)
      maxUpdate(res[i][j], a[i][k] + b[k][j]);
  }
}
int V, K, E, dp[155][155], prv[155][155];
vector<vector<Edge>> adj;
void restore(int step, int v) {
  int c = step;
  vector<int> path;
  while (v != -1) {
    path.push_back(v);
    v = prv[c--][v];
  }
  reverse(path.begin(), path.end());
  for_(i, 0, step + 1) cout << path[i] << (i < step ? " " : "\n");
}
bool shortPhase() {
  memset(dp, -1, sizeof(dp));
  memset(prv, -1, sizeof(prv));
  for_(v, 0, V) dp[0][v] = 0;
  int max_score = -1, step = -1, terminal = -1;
  for_(i, 0, 150) {
    for_(v, 0, V) {
      if (dp[i][v] == -1)
        continue;
      for (Edge e : adj[v]) {
        if (dp[i + 1][e.to] < dp[i][v] + e.c) {
          dp[i + 1][e.to] = dp[i][v] + e.c;
          prv[i + 1][e.to] = v;
          if (max_score < dp[i + 1][e.to]) {
            max_score = dp[i + 1][e.to];
            terminal = e.to;
          }
        }
      }
    }
    if (max_score >= K) {
      step = i + 1;
      break;
    }
  }
  if (max_score >= K) {
    cout << step << endl;
    restore(step, terminal);
    return true;
  }
  if (max_score == -1) {
    cout << -1 << endl;
    return true;
  }
  return false;
}
int calcMinStep() {
  Mat mat[21], ini(V, Ary(V, -1));
  for_(v, 0, V) for (Edge e : adj[v]) { maxUpdate(ini[v][e.to], e.c); }
  mat[0] = ini;
  for_(i, 0, 20) mul(mat[i + 1], mat[i], mat[i]);
  int res = 0;
  Mat x(V, Ary(V, -1)), nx;
  for_(v, 0, V) x[v][v] = 0;
  for_rev(h, 19, 0) {
    mul(nx, x, mat[h]);
    int max_score = 0;
    for_(u, 0, V) for_(v, 0, V) maxUpdate(max_score, nx[u][v]);
    if (max_score < K) {
      x = nx;
      res += 1 << h;
    }
  }
  return res + 1;
}
void solve() {
  if (!shortPhase()) {
    int ans = calcMinStep();
    cout << (ans > (int)1e6 ? -1 : ans) << endl;
  }
}
int main() {
  cin >> V >> E >> K;
  adj.assign(V, vector<Edge>());
  for_(i, 0, E) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u].push_back(Edge{v, c});
  }
  solve();
}
accuracy: 1
time_ms: 190
memory_kb: 5968
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define for_rev(i, a, b) for (int i = (a); i >= (b); --i)
typedef vector<int> Ary;
typedef vector<Ary> Mat;
struct Edge {
  int to, c;
};
void maxUpdate(int &a, int b) { a = max(a, b); }
void mul(Mat &res, Mat &a, Mat &b) {
  int N = a.size();
  res = a;
  for_(i, 0, N) for_(j, 0, N) for_(k, 0, N) {
    if (a[i][k] >= 0 && b[k][j] >= 0)
      maxUpdate(res[i][j], a[i][k] + b[k][j]);
  }
}
int V, K, E, dp[155][155], prv[155][155];
vector<vector<Edge>> adj;
void restore(int step, int v) {
  int c = step;
  vector<int> path;
  while (v != -1) {
    path.push_back(v);
    v = prv[c--][v];
  }
  reverse(path.begin(), path.end());
  for_(i, 0, step + 1) cout << path[i] << (i < step ? " " : "\n");
}
bool shortPhase() {
  memset(dp, -1, sizeof(dp));
  memset(prv, -1, sizeof(prv));
  for_(v, 0, V) dp[0][v] = 0;
  int max_score = -1, step = -1, terminal = -1;
  for_(i, 0, 70) {
    for_(v, 0, V) {
      if (dp[i][v] == -1)
        continue;
      for (Edge e : adj[v]) {
        if (dp[i + 1][e.to] < dp[i][v] + e.c) {
          dp[i + 1][e.to] = dp[i][v] + e.c;
          prv[i + 1][e.to] = v;
          if (max_score < dp[i + 1][e.to]) {
            max_score = dp[i + 1][e.to];
            terminal = e.to;
          }
        }
      }
    }
    if (max_score >= K) {
      step = i + 1;
      break;
    }
  }
  if (max_score >= K) {
    cout << step << endl;
    restore(step, terminal);
    return true;
  }
  if (max_score == -1) {
    cout << -1 << endl;
    return true;
  }
  return false;
}
int calcMinStep() {
  Mat mat[21], ini(V, Ary(V, -1));
  for_(v, 0, V) for (Edge e : adj[v]) { maxUpdate(ini[v][e.to], e.c); }
  mat[0] = ini;
  for_(i, 0, 20) mul(mat[i + 1], mat[i], mat[i]);
  int res = 0;
  Mat x(V, Ary(V, -1)), nx;
  for_(v, 0, V) x[v][v] = 0;
  for_rev(h, 19, 0) {
    mul(nx, x, mat[h]);
    int max_score = 0;
    for_(u, 0, V) for_(v, 0, V) maxUpdate(max_score, nx[u][v]);
    if (max_score < K) {
      x = nx;
      res += 1 << h;
    }
  }
  return res + 1;
}
void solve() {
  if (!shortPhase()) {
    int ans = calcMinStep();
    cout << (ans > (int)1e6 ? -1 : ans) << endl;
  }
}
int main() {
  cin >> V >> E >> K;
  adj.assign(V, vector<Edge>());
  for_(i, 0, E) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u].push_back(Edge{v, c});
  }
  solve();
}
accuracy: 0.3333333333333333
time_ms: 160
memory_kb: 5792
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define for_rev(i, a, b) for (int i = (a); i >= (b); --i)
typedef vector<int> Ary;
typedef vector<Ary> Mat;
struct Edge {
  int to, c;
};
void maxUpdate(int &a, int b) { a = max(a, b); }
void mul(Mat &res, Mat &a, Mat &b) {
  int N = a.size();
  res = a;
  for_(i, 0, N) for_(j, 0, N) for_(k, 0, N) {
    if (a[i][k] >= 0 && b[k][j] >= 0)
      maxUpdate(res[i][j], a[i][k] + b[k][j]);
  }
}
int V, K, E, dp[155][155], prv[155][155];
vector<vector<Edge>> adj;
void restore(int step, int v) {
  int c = step;
  vector<int> path;
  while (v != -1) {
    path.push_back(v);
    v = prv[c--][v];
  }
  reverse(path.begin(), path.end());
  for_(i, 0, step + 1) cout << path[i] << (i < step ? " " : "\n");
}
bool shortPhase() {
  memset(dp, -1, sizeof(dp));
  memset(prv, -1, sizeof(prv));
  for_(v, 0, V) dp[0][v] = 0;
  int max_score = -1, step = -1, terminal = -1;
  for_(i, 0, 80) {
    for_(v, 0, V) {
      if (dp[i][v] == -1)
        continue;
      for (Edge e : adj[v]) {
        if (dp[i + 1][e.to] < dp[i][v] + e.c) {
          dp[i + 1][e.to] = dp[i][v] + e.c;
          prv[i + 1][e.to] = v;
          if (max_score < dp[i + 1][e.to]) {
            max_score = dp[i + 1][e.to];
            terminal = e.to;
          }
        }
      }
    }
    if (max_score >= K) {
      step = i + 1;
      break;
    }
  }
  if (max_score >= K) {
    cout << step << endl;
    restore(step, terminal);
    return true;
  }
  if (max_score == -1) {
    cout << -1 << endl;
    return true;
  }
  return false;
}
int calcMinStep() {
  Mat mat[21], ini(V, Ary(V, -1));
  for_(v, 0, V) for (Edge e : adj[v]) { maxUpdate(ini[v][e.to], e.c); }
  mat[0] = ini;
  for_(i, 0, 20) mul(mat[i + 1], mat[i], mat[i]);
  int res = 0;
  Mat x(V, Ary(V, -1)), nx;
  for_(v, 0, V) x[v][v] = 0;
  for_rev(h, 19, 0) {
    mul(nx, x, mat[h]);
    int max_score = 0;
    for_(u, 0, V) for_(v, 0, V) maxUpdate(max_score, nx[u][v]);
    if (max_score < K) {
      x = nx;
      res += 1 << h;
    }
  }
  return res + 1;
}
void solve() {
  if (!shortPhase()) {
    int ans = calcMinStep();
    cout << (ans > (int)1e6 ? -1 : ans) << endl;
  }
}
int main() {
  cin >> V >> E >> K;
  adj.assign(V, vector<Edge>());
  for_(i, 0, E) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u].push_back(Edge{v, c});
  }
  solve();
}
accuracy: 0.3333333333333333
time_ms: 160
memory_kb: 5784
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define for_rev(i, a, b) for (int i = (a); i >= (b); --i)
typedef vector<int> Ary;
typedef vector<Ary> Mat;
struct Edge {
  int to, c;
};
void maxUpdate(int &a, int b) { a = max(a, b); }
void mul(Mat &res, Mat &a, Mat &b) {
  int N = a.size();
  res = a;
  for_(i, 0, N) for_(j, 0, N) for_(k, 0, N) {
    if (a[i][k] >= 0 && b[k][j] >= 0)
      maxUpdate(res[i][j], a[i][k] + b[k][j]);
  }
}
int V, K, E, dp[155][155], prv[155][155];
vector<vector<Edge>> adj;
void restore(int step, int v) {
  int c = step;
  vector<int> path;
  while (v != -1) {
    path.push_back(v);
    v = prv[c--][v];
  }
  reverse(path.begin(), path.end());
  for_(i, 0, step + 1) cout << path[i] << (i < step ? " " : "\n");
}
bool shortPhase() {
  memset(dp, -1, sizeof(dp));
  memset(prv, -1, sizeof(prv));
  for_(v, 0, V) dp[0][v] = 0;
  int max_score = -1, step = -1, terminal = -1;
  for_(i, 0, 100) {
    for_(v, 0, V) {
      if (dp[i][v] == -1)
        continue;
      for (Edge e : adj[v]) {
        if (dp[i + 1][e.to] < dp[i][v] + e.c) {
          dp[i + 1][e.to] = dp[i][v] + e.c;
          prv[i + 1][e.to] = v;
          if (max_score < dp[i + 1][e.to]) {
            max_score = dp[i + 1][e.to];
            terminal = e.to;
          }
        }
      }
    }
    if (max_score >= K) {
      step = i + 1;
      break;
    }
  }
  if (max_score >= K) {
    cout << step << endl;
    restore(step, terminal);
    return true;
  }
  if (max_score == -1) {
    cout << -1 << endl;
    return true;
  }
  return false;
}
int calcMinStep() {
  Mat mat[21], ini(V, Ary(V, -1));
  for_(v, 0, V) for (Edge e : adj[v]) { maxUpdate(ini[v][e.to], e.c); }
  mat[0] = ini;
  for_(i, 0, 20) mul(mat[i + 1], mat[i], mat[i]);
  int res = 0;
  Mat x(V, Ary(V, -1)), nx;
  for_(v, 0, V) x[v][v] = 0;
  for_rev(h, 19, 0) {
    mul(nx, x, mat[h]);
    int max_score = 0;
    for_(u, 0, V) for_(v, 0, V) maxUpdate(max_score, nx[u][v]);
    if (max_score < K) {
      x = nx;
      res += 1 << h;
    }
  }
  return res + 1;
}
void solve() {
  if (!shortPhase()) {
    int ans = calcMinStep();
    cout << (ans > (int)1e6 ? -1 : ans) << endl;
  }
}
int main() {
  cin >> V >> E >> K;
  adj.assign(V, vector<Edge>());
  for_(i, 0, E) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u].push_back(Edge{v, c});
  }
  solve();
}
accuracy: 1
time_ms: 200
memory_kb: 6044
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define for_rev(i, a, b) for (int i = (a); i >= (b); --i)
typedef vector<int> Ary;
typedef vector<Ary> Mat;
struct Edge {
  int to, c;
};
void maxUpdate(int &a, int b) { a = max(a, b); }
void mul(Mat &res, Mat &a, Mat &b) {
  int N = a.size();
  res = a;
  for_(i, 0, N) for_(j, 0, N) for_(k, 0, N) {
    if (a[i][k] >= 0 && b[k][j] >= 0)
      maxUpdate(res[i][j], a[i][k] + b[k][j]);
  }
}
int V, K, E, dp[155][155], prv[155][155];
vector<vector<Edge>> adj;
void restore(int step, int v) {
  int c = step;
  vector<int> path;
  while (v != -1) {
    path.push_back(v);
    v = prv[c--][v];
  }
  reverse(path.begin(), path.end());
  for_(i, 0, step + 1) cout << path[i] << (i < step ? " " : "\n");
}
bool shortPhase() {
  memset(dp, -1, sizeof(dp));
  memset(prv, -1, sizeof(prv));
  for_(v, 0, V) dp[0][v] = 0;
  int max_score = -1, step = -1, terminal = -1;
  for_(i, 0, 120) {
    for_(v, 0, V) {
      if (dp[i][v] == -1)
        continue;
      for (Edge e : adj[v]) {
        if (dp[i + 1][e.to] < dp[i][v] + e.c) {
          dp[i + 1][e.to] = dp[i][v] + e.c;
          prv[i + 1][e.to] = v;
          if (max_score < dp[i + 1][e.to]) {
            max_score = dp[i + 1][e.to];
            terminal = e.to;
          }
        }
      }
    }
    if (max_score >= K) {
      step = i + 1;
      break;
    }
  }
  if (max_score >= K) {
    cout << step << endl;
    restore(step, terminal);
    return true;
  }
  if (max_score == -1) {
    cout << -1 << endl;
    return true;
  }
  return false;
}
int calcMinStep() {
  Mat mat[21], ini(V, Ary(V, -1));
  for_(v, 0, V) for (Edge e : adj[v]) { maxUpdate(ini[v][e.to], e.c); }
  mat[0] = ini;
  for_(i, 0, 20) mul(mat[i + 1], mat[i], mat[i]);
  int res = 0;
  Mat x(V, Ary(V, -1)), nx;
  for_(v, 0, V) x[v][v] = 0;
  for_rev(h, 19, 0) {
    mul(nx, x, mat[h]);
    int max_score = 0;
    for_(u, 0, V) for_(v, 0, V) maxUpdate(max_score, nx[u][v]);
    if (max_score < K) {
      x = nx;
      res += 1 << h;
    }
  }
  return res + 1;
}
void solve() {
  if (!shortPhase()) {
    int ans = calcMinStep();
    cout << (ans > (int)1e6 ? -1 : ans) << endl;
  }
}
int main() {
  cin >> V >> E >> K;
  adj.assign(V, vector<Edge>());
  for_(i, 0, E) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u].push_back(Edge{v, c});
  }
  solve();
}
accuracy: 1
time_ms: 200
memory_kb: 5992
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define for_rev(i, a, b) for (int i = (a); i >= (b); --i)
typedef vector<int> Ary;
typedef vector<Ary> Mat;
struct Edge {
  int to, c;
};
void maxUpdate(int &a, int b) { a = max(a, b); }
void mul(Mat &res, Mat &a, Mat &b) {
  int N = a.size();
  res = Mat(N, Ary(N, -1));
  for_(i, 0, N) for_(j, 0, N) for_(k, 0, N) {
    if (a[i][k] >= 0 && b[k][j] >= 0)
      maxUpdate(res[i][j], a[i][k] + b[k][j]);
  }
}
int V, K, E, dp[155][155], prv[155][155];
vector<vector<Edge>> adj;
void restore(int step, int v) {
  int c = step;
  vector<int> path;
  while (v != -1) {
    path.push_back(v);
    v = prv[c--][v];
  }
  reverse(path.begin(), path.end());
  for_(i, 0, step + 1) cout << path[i] << (i < step ? " " : "\n");
}
bool shortPhase() {
  memset(dp, -1, sizeof(dp));
  memset(prv, -1, sizeof(prv));
  for_(v, 0, V) dp[0][v] = 0;
  int max_score = -1, step = -1, terminal = -1;
  for_(i, 0, 150) {
    for_(v, 0, V) {
      if (dp[i][v] == -1)
        continue;
      for (Edge e : adj[v]) {
        if (dp[i + 1][e.to] < dp[i][v] + e.c) {
          dp[i + 1][e.to] = dp[i][v] + e.c;
          prv[i + 1][e.to] = v;
          if (max_score < dp[i + 1][e.to]) {
            max_score = dp[i + 1][e.to];
            terminal = e.to;
          }
        }
      }
    }
    if (max_score >= K) {
      step = i + 1;
      break;
    }
  }
  if (max_score >= K) {
    cout << step << endl;
    restore(step, terminal);
    return true;
  }
  if (max_score == -1) {
    cout << -1 << endl;
    return true;
  }
  return false;
}
int calcMinStep() {
  Mat mat[21], ini(V, Ary(V, -1));
  for_(v, 0, V) for (Edge e : adj[v]) { maxUpdate(ini[v][e.to], e.c); }
  mat[0] = ini;
  for_(i, 0, 20) mul(mat[i + 1], mat[i], mat[i]);
  int res = 0;
  Mat x(V, Ary(V, -1)), nx;
  for_(v, 0, V) x[v][v] = 0;
  for_rev(h, 19, 0) {
    mul(nx, x, mat[h]);
    int max_score = 0;
    for_(u, 0, V) for_(v, 0, V) maxUpdate(max_score, nx[u][v]);
    if (max_score < K) {
      x = nx;
      res += 1 << h;
    }
  }
  return res + 1;
}
void solve() {
  if (!shortPhase()) {
    int ans = calcMinStep();
    cout << (ans > (int)1e6 ? -1 : ans) << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> V >> E >> K;
  adj.assign(V, vector<Edge>());
  for_(i, 0, E) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u].push_back(Edge{v, c});
  }
  solve();
}
accuracy: 0.8
time_ms: 200
memory_kb: 6008
final_rank: 14