wayList = []
def FindPath(nodeCount, costs, startIndex, endIndex):
def dijkstra(graph, start, end):
distance = [float('inf')] * nodeCount
distance[start] = 0
visited = [False] * nodeCount
path = [[] for _ in range(nodeCount)]
for _ in range(nodeCount):
min_distance = float('inf')
min_index = -1
for i in range(nodeCount):
if not visited[i] and distance[i] < min_distance:
min_distance = distance[i]
min_index = i
if min_index == -1:
break
visited[min_index] = True
for i in range(nodeCount):
if not visited[i] and graph[min_index][i] > 0:
new_distance = distance[min_index] + graph[min_index][i]
if new_distance < distance[i]:
distance[i] = new_distance
path[i] = path[min_index] + [min_index]
return path[end] + [end]
graph = [[0] * nodeCount for _ in range(nodeCount)]
for i in range(nodeCount):
for j in range(nodeCount):
graph[i][j] = costs[i][j] if i != j else 0
wayList.extend(dijkstra(graph, startIndex, endIndex))
return wayList