Updated code comments to portuguese (#20796)
This commit is contained in:
committed by
Fabio Trilho Pereira
parent
5c34c55546
commit
933cd042b0
@ -15,22 +15,22 @@ Pior complexidade do tempo de caso: O (V ^ 3)
|
|||||||
### Implementação em Python
|
### Implementação em Python
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# A large value as infinity
|
# Um valor grande significando infinito
|
||||||
inf = 1e10
|
inf = 1e10
|
||||||
|
|
||||||
def floyd_warshall(weights):
|
def floyd_warshall(weights):
|
||||||
V = len(weights)
|
V = len(weights)
|
||||||
distance_matrix = weights
|
distance_matrix = weights
|
||||||
for k in range(V):
|
for k in range(V):
|
||||||
next_distance_matrix = [list(row) for row in distance_matrix] # make a copy of distance matrix
|
next_distance_matrix = [list(row) for row in distance_matrix] # Faz uma copia da matriz de distancia
|
||||||
for i in range(V):
|
for i in range(V):
|
||||||
for j in range(V):
|
for j in range(V):
|
||||||
# Choose if the k vertex can work as a path with shorter distance
|
# Seleciona se o vertice k pode ser usado para o caminho com menor distancia
|
||||||
next_distance_matrix[i][j] = min(distance_matrix[i][j], distance_matrix[i][k] + distance_matrix[k][j])
|
next_distance_matrix[i][j] = min(distance_matrix[i][j], distance_matrix[i][k] + distance_matrix[k][j])
|
||||||
distance_matrix = next_distance_matrix # update
|
distance_matrix = next_distance_matrix # update
|
||||||
return distance_matrix
|
return distance_matrix
|
||||||
|
|
||||||
# A graph represented as Adjacency matrix
|
# Grafo representa uma matriz de adjacencias
|
||||||
graph = [
|
graph = [
|
||||||
[0, inf, inf, -3],
|
[0, inf, inf, -3],
|
||||||
[inf, 0, inf, 8],
|
[inf, 0, inf, 8],
|
||||||
|
Reference in New Issue
Block a user