Language: C++

#inport
import sys
import numpy as np

#input
N,M = map(int, sys.stdin.readline().split())
P = [list(map(int, sys.stdin.readline().split())) for i in range(M)]

#shori
##初期化
ans = np.zeros((N,3))
tmp_latest = np.zeros(1)
tmp_latest_tmp = np.zeros(1)
tmp_latest[0] = 1
pos_latest = 0
num_latest = 1
ans[0][1] = 1 #部屋1をてがかりありに
ans[0][2] = 1 #部屋1をてがかりありに
flg_pos = 1
flg_fale = 0
num_crew = 0

for i in range(N):
    ans[i][0] = i + 1

while num_crew < N:
    if flg_pos == 0:
        flg_fale = 1
        break

    flg_pos = 0
    for i in range(N):
        if ans[i][2] == 0:
            #手がかりが置いてなければ置ける手がかりを探索
            tmp_room_num = ans[i][0]

            for j in range(M):
                if P[j][1] == tmp_room_num:
                    if P[j][0] in tmp_latest:
                        ans[P[j][1]-1][1] = P[j][0]
                        ans[P[j][1]-1][2] = 1
                        tmp_latest_tmp = np.insert(tmp_latest_tmp, 0, tmp_room_num)
                        flg_pos = 1
                        break
                elif P[j][0] == tmp_room_num: 
                    if P[j][1] in tmp_latest:
                        ans[P[j][0]-1][1] = P[j][1]
                        ans[P[j][0]-1][2] = 1
                        tmp_latest_tmp = np.insert(tmp_latest_tmp, 0, tmp_room_num)
                        flg_pos = 1
                        break

    #Nループ終了時にtmp_latestを更新
    tmp_latest = np.insert(tmp_latest, num_latest, tmp_latest_tmp)
    for j in range(num_latest):
        tmp_latest = np.delete(tmp_latest,0)
    
    num_latest = np.size(tmp_latest)
    num_crew = np.sum(ans,axis = 0)[2]

if flg_fale == 0:
    print('Yes')
    for i in range(N-1):
        print(int(ans[i+1][1]))
else:
    print('No')


Compiler output:
a.cc:1:2: error: invalid preprocessing directive #inport; did you mean #import?
    1 | #inport
      |  ^~~~~~
      |  import
a.cc:5:2: error: invalid preprocessing directive #input
    5 | #input
      |  ^~~~~
a.cc:9:2: error: invalid preprocessing directive #shori
    9 | #shori
      |  ^~~~~
a.cc:10:1: error: stray '##' in program
   10 | ##初期化
      | ^~
a.cc:17:15: error: stray '#' in program
   17 | ans[0][1] = 1 #部屋1をてがかりありに
      |               ^
a.cc:18:15: error: stray '#' in program
   18 | ans[0][2] = 1 #部屋1をてがかりありに
      |               ^
a.cc:34:14: error: invalid preprocessing directive #\U0000624b\U0000304c\U0000304b\U0000308a\U0000304c\U00007f6e\U00003044\U00003066\U0000306a\U00003051\U0000308c\U00003070\U00007f6e\U00003051\U0000308b\U0000624b\U0000304c\U0000304b\U0000308a\U00003092\U000063a2\U00007d22
   34 |             #手がかりが置いてなければ置ける手がかりを探索
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:53:6: error: invalid preprocessing directive #N\U000030eb\U000030fc\U000030d7\U00007d42\U00004e86\U00006642\U0000306btmp_latest\U00003092\U000066f4\U000065b0
   53 |     #Nループ終了時にtmp_latestを更新
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:62:11: warning: multi-character character constant [-Wmultichar]
   62 |     print('Yes')
      |           ^~~~~
a.cc:66:11: warning: multi-character character constant [-Wmultichar]
   66 |     print('No')
      |           ^~~~
a.cc:2:1: error: 'import' does not name a type
    2 | import sys
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'