Language: C++

import sys
input = sys.stdin.readline

def dijkstra(n, edge, s, t):
    unserched = list(range(n))
    comp = [0] * n
    dist = [n] * n
    # prenode = [-1] * n
    
    dist[s] = 0
    endflag = False
    while(not endflag):
        # 未確定の点のうち距離が最小のものを求める
        min_dist = n
        min_dist_node = -1
        for node in unserched:
            if dist[node] < min_dist:
                min_dist = dist[node]
                min_dist_node = node
        if min_dist_node == -1:
            dist[t] = -1
            break
        if min_dist_node == t:
            endflag = True

        unserched.remove(min_dist_node)
         
        for e in edge[min_dist_node]:
            if comp[e] == 0: # and dist[e] > min_dist + 1:
                comp[e] = 1
                dist[e] = min_dist + 1
                # prenode[e] = min_dist_node
    # ptr = t
    # while ptr != s:
    #     print(ptr)
    #     ptr = prenode[ptr]
    # print(ptr)
    return dist[t]

n, m = map(int, input().split())
u = [list(map(int, input().split())) for _ in range(m)]
s, t = map(int, input().split())

edge = [[] for _ in range(n*3)]
for i in range(m):
    edge[u[i][0]-1].append(u[i][1]-1 + n)
    edge[u[i][0]-1 + n].append(u[i][1]-1 + 2*n)
    edge[u[i][0]-1 + 2*n].append(u[i][1]-1)

# for i in range(m):
#     print(u[i][0], u[i][1])

# for i, e in enumerate(edge):
#     for j in e:
#         print(i,j)
# print(edge)

print(dijkstra(n*3, edge, s-1, t-1)//3)


Compiler output:
a.cc:8:7: error: invalid preprocessing directive #prenode
    8 |     # prenode = [-1] * n
      |       ^~~~~~~
a.cc:13:11: error: invalid preprocessing directive #\U0000672a\U000078ba\U00005b9a\U0000306e\U000070b9\U0000306e\U00003046\U00003061\U00008ddd\U000096e2\U0000304c\U00006700\U00005c0f\U0000306e\U00003082\U0000306e\U00003092\U00006c42\U00003081\U0000308b
   13 |         # 未確定の点のうち距離が最小のものを求める
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:29:30: error: stray '#' in program
   29 |             if comp[e] == 0: # and dist[e] > min_dist + 1:
      |                              ^
a.cc:32:19: error: invalid preprocessing directive #prenode
   32 |                 # prenode[e] = min_dist_node
      |                   ^~~~~~~
a.cc:33:7: error: invalid preprocessing directive #ptr
   33 |     # ptr = t
      |       ^~~
a.cc:34:7: error: invalid preprocessing directive #while
   34 |     # while ptr != s:
      |       ^~~~~
a.cc:35:11: error: invalid preprocessing directive #print
   35 |     #     print(ptr)
      |           ^~~~~
a.cc:36:11: error: invalid preprocessing directive #ptr
   36 |     #     ptr = prenode[ptr]
      |           ^~~
a.cc:37:7: error: invalid preprocessing directive #print
   37 |     # print(ptr)
      |       ^~~~~
a.cc:50:3: error: invalid preprocessing directive #for
   50 | # for i in range(m):
      |   ^~~
a.cc:51:7: error: invalid preprocessing directive #print
   51 | #     print(u[i][0], u[i][1])
      |       ^~~~~
a.cc:53:3: error: invalid preprocessing directive #for
   53 | # for i, e in enumerate(edge):
      |   ^~~
a.cc:54:7: error: invalid preprocessing directive #for
   54 | #     for j in e:
      |       ^~~
a.cc:55:11: error: invalid preprocessing directive #print
   55 | #         print(i,j)
      |           ^~~~~
a.cc:56:3: error: invalid preprocessing directive #print
   56 | # print(edge)
      |   ^~~~~
a.cc:1:1: error: 'import' does not name a type
    1 | import sys
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'