PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BF0000041. Trò chơi đua xe (Racing Game)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Trò chơi đua xe (Racing Game)
Racing Game
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
Assign an integer length between and to every directed edge, so that every walk from vertex to vertex has the same total length. Walks may repeat vertices. Output -1 if there is no walk from to or no valid assignment exists.
Input
First line , followed by ordered directed edges .
Output
Print -1, or print and then triples in their input order, with .
Subtasks
- Subtask 1 (30 points): , ; , ; no repeated directed edge.
- Subtask 2 (30 points): , ; , ; no repeated directed edge.
- Subtask 3 (40 points): , ; , ; no repeated directed edge.
Examples
Input
3 3
1 2
2 3
1 3
Output
3 3
1 2 1
2 3 1
1 3 2
Explanation
There are two walks from to : the direct edge and the two-edge route through . Assigning weights gives both walks total length , while every edge length lies between and .