from heapq import heappop,heappush class Heap_Point: def __init__(self,x,d): self.d=d self.x=x def __str__(self): return "(point:{}, dist:{})".format(self.x,self.d) def __repr__(self): return str(self) def __lt__(self,other): return self.dcost+Ai[k]: Ti[k]=cost+Ai[k] heappush(Q,Heap_Point((i,k),Ti[k])) else: alpha=cost+A[i+1][j] if T[i+1][j]>alpha: T[i+1][j]=alpha heappush(Q, Heap_Point((i+1,j),T[i+1][j])) if U[i+1]>alpha: U[i+1]=alpha heappush(Q, Heap_Point((i+1,-1),U[i+1])) #================================================== print(solve())