(
node_count: int, edge_count: int
)
| 33 | |
| 34 | |
| 35 | def initialize_weighted_undirected_graph( |
| 36 | node_count: int, edge_count: int |
| 37 | ) -> dict[int, list[tuple[int, int]]]: |
| 38 | graph: dict[int, list[tuple[int, int]]] = {} |
| 39 | for i in range(node_count): |
| 40 | graph[i + 1] = [] |
| 41 | |
| 42 | for e in range(edge_count): |
| 43 | x, y, w = (int(i) for i in _input(f"Edge {e + 1}: <node1> <node2> <weight> ")) |
| 44 | graph[x].append((y, w)) |
| 45 | graph[y].append((x, w)) |
| 46 | return graph |
| 47 | |
| 48 | |
| 49 | if __name__ == "__main__": |