def firstsolve(): re=[] point=BFS(St,K) for b in BFS_Restoration(K,point)[::-1]: re.append(b) point=BFS(K,G) for b in BFS_Restoration(G,point)[::-1]: re.append(b) return re def BFS_Restoration(end,point): thispoint=point[end[0]*N+end[1]] pos=end re=[pos] while thispoint!=0: for d in [[1,0],[-1,0],[0,1],[0,-1]]: x=pos[0]+d[0] y=pos[1]+d[1] if 0