PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000087. Hai người gặp nhau (Collision)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hai người gặp nhau (Collision)
Collision
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are towns connected by equally long undirected roads forming a tree. In each query , two travelers leave simultaneously from towns , heading toward each other along the unique shortest route at equal speeds. Determine whether they meet at a town or midway along a road.
Input
First line: . Then edges and queries .
Output
Print Town if they meet at a town, otherwise Road, one line per query.
Subtasks
-
Subtask 1 (20 points): ; ; ; ; edges form a tree vô hướng.
-
Subtask 2 (30 points): ; ; ; ; edges form a tree vô hướng.
-
Subtask 3 (50 points): ; ; ; ; edges form a tree vô hướng.
Examples
Input
5 2
1 2
2 3
3 4
4 5
1 3
1 5
Output
Town
Town
Explanation
Both distances have an even number of edges ( and ), so the midpoint is a town.