def prim(graph,n):
state =[0for i inrange(n)]
dist =[float("inf")for _ inrange(n)]
result =[]for i inrange(n):if dist[0]==float("inf"):
idx =0
dist[0]=0else:
mx =float("inf")for i inrange(n):if dist[i]< mx and not state[i]:
mx =dist[i]
idx = i
result.append(idx)
state[idx]=1for i inrange(n):if graph[i][idx]< dist[i] and not state[i]:
dist[i]= graph[i][idx]return result
if __name__ =='__main__':
graph =[[1,5,3,6],[5,8,9,6],[3,9,8,6],[6,6,6,3]]print(prim(graph,4))