Language: C++

#include <bits/stdc++.h>

int main(){
    int N, M, L, Q;
    std::cin >> N >> M >> L;
    std::vector< std::vector< int > > AB(N);
    std::vector< std::vector< int > > ABC(N, std::vector< int >(N, -1));
    for(int i=0; i<M; i++){
        int tmpa, tmpb, tmpc;
        std::cin >> tmpa >> tmpb >> tmpc;
        tmpa--;
        tmpb--;
        AB[tmpa].push_back(tmpb);
        AB[tmpb].push_back(tmpa);
        ABC[tmpa][tmpb] = tmpc;
        ABC[tmpb][tmpa] = tmpc;
    }
    std::cin >> Q;
    std::vector< int > S(Q);
    std::vector< int > T(Q);
    for(int i=0; i<Q; i++){
        std::cin >> S[i] >> T[i];
        S[i]--;
        T[i]--;
    }
    
    std::vector< std::vector< int > > AB_1step(N);
    
    for(int i=0; i<N; i++){
        std::vector< int > min_cost(N, 1e9+1);
        std::vector< bool > pass(N, false);
        std::deque< int > pos;
        std::deque< int > cost;
        pos.push_back(i);
        cost.push_back(0);
        while(!pos.empty()){
            int cur_pos = pos[0];
            int cur_cost = cost[0];
            pos.pop_front();
            cost.pop_front();
            if(pass[cur_pos]){
                continue;
            }
            if(min_cost[cur_pos] < cur_cost){
                continue;
            }
            if(cur_cost > L){
                continue;
            }
            
            min_cost[cur_pos] = cur_cost;
            pass[cur_pos] = true;
            for(int j=0; j<AB[cur_pos].size(); j++){
                pos.push_back(AB[cur_pos][j]);
                cost.push_back(cur_cost + ABC[cur_pos][AB[cur_pos][j]]);
            }
        }
        for(int j=0; j<N; j++){
            if(min_cost[j] <= L && i != j){
                AB_1step[i].push_back(j);
            }
        }
    }
    
    std::vector< std::vector< int > > StoTmin(N, std::vector< int >(N))
    for(int i=0; i<N; i++){
        std::vector< int > min_cost(N, 1e9+1);
        std::deque< int > pos;
        std::deque< int > cost;
        for(int j=0; j<AB_1step[S[i]].size(); j++){
            pos.push_back(AB_1step[S[i]][j]);
            cost.push_back(0);
        }
        while(!pos.empty()){
            int cur_pos = pos[0];
            int cur_cost = cost[0];
            pos.pop_front();
            cost.pop_front();
            
            if(min_cost[cur_pos] < cur_cost){
                continue;
            }
            
            min_cost[cur_pos] = cur_cost;
            for(int j=0; j<AB_1step[cur_pos].size(); j++){
                pos.push_back(AB_1step[cur_pos][j]);
                cost.push_back(cur_cost + 1);
            }
        }
        for(int j=0; j<N; j++){
            StoTmin[i][j] = min_cost[j];
        }
    }
    
    for(int i=0; i<Q; i++){
        if(StoTmin[S[i][T[i]] == 1e9+1){
            std::cout << -1 << std::endl;
        }else{
            std::cout << min_cost[T[i]] << std::endl;
        }
    }
    
    return 0;
    
}


Compiler output:
a.cc: In function 'int main()':
a.cc:66:5: error: expected ',' or ';' before 'for'
   66 |     for(int i=0; i<N; i++){
      |     ^~~
a.cc:66:18: error: 'i' was not declared in this scope
   66 |     for(int i=0; i<N; i++){
      |                  ^
a.cc:96:24: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}]' for array subscript
   96 |         if(StoTmin[S[i][T[i]] == 1e9+1){
      |                        ^
a.cc:96:39: error: expected ']' before ')' token
   96 |         if(StoTmin[S[i][T[i]] == 1e9+1){
      |                                       ^
      |                                       ]
a.cc:99:26: error: 'min_cost' was not declared in this scope
   99 |             std::cout << min_cost[T[i]] << std::endl;
      |                          ^~~~~~~~