- Mã:
- MIN_DIS
- Tên:
- Print road
- Dạng thi:
- oi
- Thang điểm:
- 10 điểm
- Giới hạn thời gian:
- 2 giây
- Giới hạn bộ nhớ:
- 256 MB
- Được tạo bởi:
- HUSCNMT
You are
given 2 integers (N, M). N is
number of vertices, M is the number of edges. You'll also be
given a(i), b(i), w(i) where a(i) and b(i) represents
an edge from a vertex a(i) to a vertex b(i) and w(i) respresents
the weight of that edge.
Your task
is to find the shortest path from source vertex (vertex number 1)
to all other vertices v(i) where (2 <= i <= N).
Input:
First
line contains two space separated integers, (N, M) them M lines
follw, each line has 3 space separated integes a(i), b(i) and w(i).
Output:
Print the
shortest distances from the source vertex (vertex number 1) to all
other vertices v(i) where (2 <= i <= N). Print
"109" in case vertex v(i) can't be reached from
the source vertex.
Leave a
space between any 2 printed numbers.
Constrains:
(1
<= N <= 104).
(1
<= M <= 106).
(1
<= ai, bi <= N).
(1
<= wi <= 1000).
Exampale
test: |
|
Input |
Output |
5 5 1 2 5 1 3 2 3 4 1 1 4 6 3 5 5 |
5 2 3 7
|
Theme :
Mời bạn soạn code