#abc209d. D - Collision

D - Collision

Score : 400400 points

问题描述

王国高桥由 NN 个城镇和 N1N-1 条道路组成,这些城镇依次编号为 11NN。第 ii 条道路(1iN11 \leq i \leq N-1)连接城镇 aia_i 和城镇 bib_i,因此通过使用某些道路可以从任意一个城镇到达任意一个城镇。所有道路的长度均相同。

你将收到 QQ 个查询。在第 ii 个查询中 (1iQ)(1 \leq i \leq Q),给出整数 cic_idid_i,解决以下问题:

  • 高桥现在位于城镇 cic_i,而青木现在位于城镇 did_i。他们将同时离开各自的城镇,并以相同速度开始旅行,高桥朝着城镇 did_i 行进,青木朝着城镇 cic_i 行进。判断他们将在某个城镇相遇还是在半路上相遇。在此假设两者都沿最短路径行进,并且穿越城镇所需的时间可以忽略不计。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

The Kingdom of Takahashi is made up of NN towns and N1N-1 roads, where the towns are numbered 11 through NN. The ii-th road (1iN1)(1 \leq i \leq N-1) connects Town aia_i and Town bib_i, so that you can get from every town to every town by using some roads. All the roads have the same length.

You will be given QQ queries. In the ii-th query (1iQ)(1 \leq i \leq Q), given integers cic_i and did_i, solve the following problem:

  • Takahashi is now at Town cic_i and Aoki is now at Town did_i. They will leave the towns simultaneously and start traveling at the same speed, Takahashi heading to Town did_i and Aoki heading to Town cic_i. Determine whether they will meet at a town or halfway along a road. Here, assume that both of them travel along the shortest paths, and the time it takes to pass towns is negligible.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1Q1051 \leq Q \leq 10^5
  • 1ai<biN(1iN1)1 \leq a_i < b_i \leq N\, (1 \leq i \leq N-1)
  • 1ci<diN(1iQ)1 \leq c_i < d_i \leq N\, (1 \leq i \leq Q)
  • All values in input are integers.
  • It is possible to get from every town to every town by using some roads.

Input

Input is given from Standard Input in the following format:

NN QQ

a1a_1 b1b_1

a2a_2 b2b_2

\hspace{0.6cm}\vdots

aN1a_{N-1} bN1b_{N-1}

c1c_1 d1d_1

c2c_2 d2d_2

\hspace{0.6cm}\vdots

cQc_Q dQd_Q

Output

Print QQ lines. The ii-th line (1iQ)(1 \leq i \leq Q) should contain Town if Takahashi and Aoki will meet at a town in the ii-th query, and Road if they meet halfway along a road in that query.

Sample Input 1

4 1
1 2
2 3
2 4
1 2

Sample Output 1

Road

In the first and only query, Takahashi and Aoki simultaneously leave Town 11 and Town 22, respectively, and they will meet halfway along the 11-st road, so we should print Road.

Sample Input 2

5 2
1 2
2 3
3 4
4 5
1 3
1 5

Sample Output 2

Town
Town

In the first query, Takahashi and Aoki simultaneously leave Town 11 and Town 33, respectively, and they will meet at Town 22, so we should print Town.

In the first query, Takahashi and Aoki simultaneously leave Town 11 and Town 55, respectively, and they will meet at Town 33, so we should print Town.

Sample Input 3

9 9
2 3
5 6
4 8
8 9
4 5
3 4
1 9
3 7
7 9
2 5
2 6
4 6
2 4
5 8
7 8
3 6
5 6

Sample Output 3

Town
Road
Town
Town
Town
Town
Road
Road
Road

update @ 2024/3/10 09:22:59