Submit | All submissions | Best solutions | Back to list |
EIMINDISTA - Min Distance to Vertices |
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
- 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 Output: 81 78 55 -1
Added by: | Ha Minh Ngoc |
Date: | 2024-06-05 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG FSHARP GO JAVA JS-MONKEY NODEJS PHP PYTHON PYPY PYPY3 PYTHON3 RUBY SQLITE SWIFT VB.NET |