
n = 7 # vertices number
matrix = [
    [0,7,5,12,99,99,99],
    [5,0,2,1,8,99,99],
    [6,1,0,2,99,9,99],
    [5,2,5,0,6,8,12],
    [99,5,99,7,0,7,10],
    [99,99,9,3,7,0,3],
    [99,99,99,11,5,6,0],
    ]



# v records access information of each node 
v = [0]*n 
# dis is the distance between start node and other nodes
dis = matrix[0].copy()

# start
v[0] = 1
dis[0] = 99

# loop 
for _ in range(n):
    # find the adjacent and nearest node
    k = 0
    for j in range(n):
        if v[j] == 0 and dis[j] < dis[k]:
            k = j
	# this node is accessed 
    v[k] = 1

    # relaxation
    for j in range(n):
        if v[j] == 0 and dis[k] + matrix[k][j] < dis[j]:
            dis[j] = dis[k] + matrix[k][j]

print(dis)