Language: C++


using namespace std;
typedef long long ll;



int main(){
    int N, M; cin >> N >> M; 
    vector<vector<int>> G(N);
    for(int i = 0; i < M; i++){
        int v, w; cin >> v >> w;
        v--;w--;
        G[v].push_back(w);
        //G[w].push_back(v);
    }
    int S, T; cin >> S >> T; S--; T--;

    vector<vector<ll>> Dist(3, vector<ll>(N));
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < N; j++) Dist[i][j] = -1;
    }

    queue<pair<int, int>> Q;
    Q.push(make_pair(0, S));
    Dist[0][S] = 0;
    while(!Q.empty()){
        auto q = Q.front(); Q.pop();
        int x = q.second;
        int c = q.first;
        int nc = (c+1)%3;
        //cout << x << "    " << c << endl;
        for(auto v : G[x]){
            //cout << x << "  " << c << "         " << v <<"  " << nc << endl;
            if(Dist[nc][v] == -1){
                Dist[nc][v] = Dist[c][x]+1;
                Q.push(make_pair(nc, v));
            }
        }
    }
    cout << Dist[0][T]/3 << endl;


}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:15: error: 'cin' was not declared in this scope
    8 |     int N, M; cin >> N >> M;
      |               ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | 
a.cc:9:5: error: 'vector' was not declared in this scope
    9 |     vector<vector<int>> G(N);
      |     ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | 
a.cc:9:19: error: expected primary-expression before 'int'
    9 |     vector<vector<int>> G(N);
      |                   ^~~
a.cc:13:9: error: 'G' was not declared in this scope
   13 |         G[v].push_back(w);
      |         ^
a.cc:18:21: error: expected primary-expression before '>>' token
   18 |     vector<vector<ll>> Dist(3, vector<ll>(N));
      |                     ^~
a.cc:18:41: error: expected primary-expression before '>' token
   18 |     vector<vector<ll>> Dist(3, vector<ll>(N));
      |                                         ^
a.cc:18:24: error: 'Dist' was not declared in this scope
   18 |     vector<vector<ll>> Dist(3, vector<ll>(N));
      |                        ^~~~
a.cc:23:5: error: 'queue' was not declared in this scope
   23 |     queue<pair<int, int>> Q;
      |     ^~~~~
a.cc:1:1: note: 'std::queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
  +++ |+#include <queue>
    1 | 
a.cc:23:11: error: 'pair' was not declared in this scope
   23 |     queue<pair<int, int>> Q;
      |           ^~~~
a.cc:1:1: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
  +++ |+#include <utility>
    1 | 
a.cc:23:16: error: expected primary-expression before 'int'
   23 |     queue<pair<int, int>> Q;
      |                ^~~
a.cc:24:5: error: 'Q' was not declared in this scope
   24 |     Q.push(make_pair(0, S));
      |     ^
a.cc:24:12: error: 'make_pair' was not declared in this scope
   24 |     Q.push(make_pair(0, S));
      |            ^~~~~~~~~
a.cc:24:12: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
a.cc:32:22: error: 'G' was not declared in this scope
   32 |         for(auto v : G[x]){
      |                      ^
a.cc:40:5: error: 'cout' was not declared in this scope
   40 |     cout << Dist[0][T]/3 << endl;
      |     ^~~~
a.cc:40:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:40:29: error: 'endl' was not declared in this scope
   40 |     cout << Dist[0][T]/3 << endl;
      |                             ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 |