EIMINDISTA - Min Distance to Vertices

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Hà Minh Ngọc
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

You are given an undirected graph with ~n~ vertices and ~m~ edges. Your task is to calculate the shortest path length from vertex ~0~ to other vertices and print them, if there is no path, print out -1.

Input

  • First line contains ~n~ and ~m~ ~(n, m \le 10^5)~
  • Next ~m~ lines, each line contains three integers represent for and edge: vertex1, vertex2 and length

Output

  • Print out shortest path length from vertex ~0~ to other vertices

Example Input

5 35 3
0 3 55
2 1 3
2 0 78

Example Output

81 78 55 -1

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.