Pondo Shortest Paths
Problem Statement
You are given a connected undirected graph with vertices and edges with weights. For all pairs of vertices, determine the shortest path between them.
Input Format
Your first line will contain two space-separated integers and . Your next lines will contain three integers each , and where and represent the endpoints of the edge and represents the weight.
Output Format
You should output lines. The line should contain all space-separated where is the shortest path from to .
Constraints
YOU CAN HAVE EDGES BETWEEN THE SAME NODES
Sample Cases
Input 1
4 5
1 2 5
1 3 9
2 3 1
4 2 3
3 4 2
Output 1
0 5 6 8
5 0 1 3
6 1 0 2
8 3 2 0
Template
n, m = map(int, input().split())
edges = [None] * m
for i in range(m):
u, v, w = map(int, input().spilt())
edges[i] = (u, v, w)
# print your output
Comments