PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000222. Đường đi ngắn nhất I (Shortest Routes I)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đường đi ngắn nhất I (Shortest Routes I)
Shortest Routes I
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
You have cities and directed flights. City is the starting point. A flight from to has positive length . Multiple flights between the same endpoints may exist.
Determine the shortest distance from city to every city. All cities are guaranteed to be reachable from city .
Input
- The first line contains .
- Each of the next lines contains , a directed flight from to of length . Cities are numbered through .
Output
Print integers in city order : the shortest distances from city .
Subtasks
- Subtask 1 (20 points): ; ; ; ; mọi đỉnh đến được từ đỉnh 1; cho phép cạnh trùng và khuyên.
- Subtask 2 (30 points): ; ; ; ; mọi đỉnh đến được từ đỉnh 1; cho phép cạnh trùng và khuyên.
- Subtask 3 (50 points): ; ; ; ; mọi đỉnh đến được từ đỉnh 1; cho phép cạnh trùng và khuyên.
Examples
Input
3 4
1 2 6
1 3 2
3 2 3
1 3 4
Output
0 5 2
Explanation
To reach city costs . To city , use the direct flight of length rather than the one of length . To city , take of length , shorter than the direct length . Thus the output is 0 5 2.