Language: Java

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

const int MOD = 1e9+7;
const int mxN = 300005;

int N,M;

vector<int>adj[mxN];
bool visited[mxN];

int dist[mxN];

void init()
{
    for(int i = 0 ; i < mxN; i++)
    {
        visited[i] = false;
        dist[i] = 0;
    }
}

void printVec(vector<int>V)
{
    for(int i = 0; i < V.size(); i++)
        cout<<V[i]<<" ";
    cout<<endl;
}

void dfs(int s)
{
    visited[s] = true;

    cout<<s<<" ";

    for(int i = 0 ; i < adj[s].size(); i++)
        if(!visited[adj[s][i]])
            dfs(adj[s][i]);
}

void bfs(int s)
{
    queue<int>q;

    visited[s] = true;

    q.push(s);

    while(!q.empty())
    {
        int p = q.front();
        q.pop();

        //cout<<p<<" ";

        for(int i = 0; i < adj[p].size(); i++)
        {
            if(!visited[adj[p][i]])
            {
                visited[adj[p][i]] = true;
                dist[adj[p][i]] = dist[p] + 1;
                q.push(adj[p][i]); 
            }
        }
    }
}

void solve()
{
    init();

    cin>>N>>M; //nodes and edges

    int x,y;

    for(int i = 0; i < M ;i++)
    {
        cin>>x>>y;
        adj[x].pb(y + N);
        adj[x + N].pb(y + 2*N);
        adj[x + 2*N].pb(y);
    }

    int src,dest;
    cin>>src>>dest;

    bfs(src);
    //cout<<endl;

    if(visited[dest])
        cout<<dist[dest]/3<<endl;
    else
        cout<<-1<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include<bits/stdc++.h>
^
Main.java:1: error: class, interface, enum, or record expected
#include<bits/stdc++.h>
        ^
Main.java:3: error: illegal character: '#'
#define ll long long
^
Main.java:3: error: class, interface, enum, or record expected
#define ll long long
        ^
Main.java:4: error: illegal character: '#'
#define pb push_back
^
Main.java:7: error: class, interface, enum, or record expected
const int mxN = 300005;
^
Main.java:9: error: class, interface, enum, or record expected
int N,M;
^
Main.java:11: error: class, interface, enum, or record expected
vector<int>adj[mxN];
^
Main.java:12: error: class, interface, enum, or record expected
bool visited[mxN];
^
Main.java:14: error: class, interface, enum, or record expected
int dist[mxN];
^
Main.java:16: error: unnamed classes are a preview feature and are disabled by default.
void init()
^
  (use --enable-preview to enable unnamed classes)
Main.java:28: error: not a statement
        cout<<V[i]<<" ";
                  ^
Main.java:29: error: not a statement
    cout<<endl;
        ^
Main.java:36: error: not a statement
    cout<<s<<" ";
           ^
Main.java:74: error: not a statement
    cin>>N>>M; //nodes and edges
          ^
Main.java:80: error: not a statement
        cin>>x>>y;
              ^
Main.java:87: error: not a statement
    cin>>src>>dest;
            ^
Main.java:93: error: not a statement
        cout<<dist[dest]/3<<endl;
                          ^
Main.java:95: error: not a statement
        cout<<-1<<endl;
                ^
Main.java:100: error: not a statement
    ios_base::sync_with_stdio(0);
    ^
Main.java:100: error: ';' expected
    ios_base::sync_with_stdio(0);
                             ^
21 errors