Language: C++

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

long long go(vector<int> &A, vector<int> &B, vector<int> &C, long long s, long long &t, long long M, long long &L, long long Lmax, long long &cnt){
    for(long long i=0; i<M; i++){
        if(B.at(i) == t){
            if(A.at(i) == s){
                if(C.at(i) <= L){
                    return cnt;
                }
                else{
                    if(C.at(i) <= Lmax){
                        cnt++;
                        return cnt;
                    }
                    else{
                        cnt = -1;
                        return cnt;
                    }
                }
            }
            else{
//                cout << "L1 = "<< L << " cnt1 = " << cnt << " C = " << C.at(i) << endl;
                L = L - C.at(i);
                if(L <= 0){
                    L = Lmax - C.at(i);
                    cnt++;
                }
//                cout << "L2 = "<< L << " cnt2 = " << cnt << endl;                
                long long tmp = go(A, B, C, s, A.at(i), M, L, Lmax, cnt);
            }
        }
    }

    return cnt;
}

long long main() {
    long long N, M = 0;
    long long L = 0;
    cin >> N >> M >> L;

    vector<int> A(M, 0);
    vector<int> B(M, 0);
    vector<long long> C(M, 0);
    for(long long i=0; i<M; i++){
        cin >> A.at(i) >> B.at(i) >> C.at(i);
    }

    long long Q=0;
    cin >> Q;

    vector<int> s(Q, 0);
    vector<int> t(Q, 0);

    long long a=0;
    for(long long i=0; i<Q; i++){
        cin >> s.at(i) >> t.at(i);
        if(s.at(i) > t.at(i)){
            a = s.at(i);
            s.at(i) = t.at(i);
            t.at(i) = a; 
        }
    }

    if(M == 0){
        cout << "-1" << endl;
        return 0;
    }

    long long cnt=0;
    long long Lmax = L;
    for(long long i=0; i<Q; i++){
        long long tmp = go(A, B, C, s.at(i), t.at(i), M, L, Lmax, cnt);
        cnt = 0;
        L = Lmax;
        cout << tmp << endl;
    }

}


Compiler output:
a.cc: In function 'long long int go(std::vector<int>&, std::vector<int>&, std::vector<int>&, long long int, long long int&, long long int, long long int&, long long int, long long int&)':
a.cc:30:52: error: cannot bind non-const lvalue reference of type 'long long int&' to a value of type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   30 |                 long long tmp = go(A, B, C, s, A.at(i), M, L, Lmax, cnt);
      |                                                ~~~~^~~
a.cc:4:86: note:   initializing argument 5 of 'long long int go(std::vector<int>&, std::vector<int>&, std::vector<int>&, long long int, long long int&, long long int, long long int&, long long int, long long int&)'
    4 | long long go(vector<int> &A, vector<int> &B, vector<int> &C, long long s, long long &t, long long M, long long &L, long long Lmax, long long &cnt){
      |                                                                           ~~~~~~~~~~~^
At global scope:
cc1plus: error: '::main' must return 'int'
a.cc: In function 'int main()':
a.cc:74:34: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::vector<long long int>'
   74 |         long long tmp = go(A, B, C, s.at(i), t.at(i), M, L, Lmax, cnt);
      |                                  ^
a.cc:4:59: note: in passing argument 3 of 'long long int go(std::vector<int>&, std::vector<int>&, std::vector<int>&, long long int, long long int&, long long int, long long int&, long long int, long long int&)'
    4 | long long go(vector<int> &A, vector<int> &B, vector<int> &C, long long s, long long &t, long long M, long long &L, long long Lmax, long long &cnt){
      |                                              ~~~~~~~~~~~~~^