# Agar yangi masofa avvalgi masofadan kichik bo'lsa, yangilanadi
if distance < distances[neighbor]:
distances[neighbor] = distance
return distances
graph = {
'A': {'B': 7, 'D': 5 },
'B': {'A': 7, 'D': 9, 'C': 8, 'E': 7},
'C': {'B': 8, 'E': 5 },
'D': {'A': 5, 'B': 9, 'F': 6, 'E': 15},
'E': {'C': 5, 'D': 15, 'F': 8, 'B': 7, 'G': 9},
'F': {'D': 6, 'E': 8, 'G': 11 },
'G': {'F': 11, 'E': 9 }
}
start_node = 'A'
distances = xasislik(graph, start_node)
print("Eng kichik daraxt:")
for node in sorted(distances):
print(f"{start_node} dan {node} ga masofa: {distances[node]}")