v_values.append(int(vertex_value)) if vertex_neighbour_1 != "E": v_destination_1.append(int(vertex_neighbour_1)) else: v_destination_1.append(-1) if vertex_neighbour_2 != "E": v_destination_2.append(int(vertex_neighbour_2)) else: v_destination_2.append(-1) # create graph g = Graph(flag_dag=True) for name in v_names: g.add_vertex(name) if v_destination_1[name] != -1: g.add_edge(GraphEdge(name, v_destination_1[name], v_values[v_destination_1[name]])) if v_destination_2[name] != -1: g.add_edge(GraphEdge(name, v_destination_2[name], v_values[v_destination_2[name]])) #print(g.edges(), file=sys.stderr) #print(g.vertices(), file=sys.stderr) #print(g.find_longest_path(0), file=sys.stderr) max_dist = max([value for key, value in g.find_longest_path(0).items()]) + v_values[0] # Write an action using print # To debug: print("Debug messages...", file=sys.stderr) print(max_dist)