text: def dijkstra(graph, start):
      """
      Implementation of dijkstra using adjacency matrix.
      This returns an array containing the length of the shortest path from the start node to each other node.
      It is only guaranteed to return correct results if there are no negative edges in the graph. Positive cycles are fine.
      This has a runtime of O(|V|^2) (|V| = number of Nodes), for a faster implementation see @see ../fast/Dijkstra.java (using adjacency lists)
  
      :param graph: an adjacency-matrix-representation of the graph where (x,y) is the weight of the edge or 0 if there is no edge.
      :param start: the node to start from.
      :return: an array containing the shortest distances from the given start node to each other node
      """
      # This contains the distances from the start node to all other nodes
      distances = [float("inf") for _ in range(len(graph))]
  
      # This contains whether a node was already visited
      visited = [False for _ in range(len(graph))]
  
      # The distance from the start node to itself is of course 0
      distances[start] = 0
  
      # While there are nodes left to visit...
      while True:
  
          # ... find the node with the currently shortest distance from the start node...
          shortest_distance = float("inf")
          shortest_index = -1
          for i in range(len(graph)):
              # ... by going through all nodes that haven't been visited yet
              if distances[i] < shortest_distance and not visited[i]:
                  shortest_distance = distances[i]
                  shortest_index = i
  
          # print("Visiting node " + str(shortest_index) + " with current distance " + str(shortest_distance))
  
          if shortest_index == -1:
              # There was no node not yet visited --> We are done
              return distances
  
          # ...then, for all neighboring nodes that haven't been visited yet....
          for i in range(len(graph[shortest_index])):
              # ...if the path over this edge is shorter...
              if graph[shortest_index][i] != 0 and distances[i] > distances[shortest_index] + graph[shortest_index][i]:
                  # ...Save this path as new shortest path.
                  distances[i] = distances[shortest_index] + graph[shortest_index][i]
                  # print("Updating distance of node " + str(i) + " to " + str(distances[i]))
  
          # Lastly, note that we are finished with this node.
          visited[shortest_index] = True
          # print("Visited nodes: " + str(visited))
          # print("Currently lowest distances: " + str(distances))
  