#P10105. [GDKOI2023 提高组] 游戏
[GDKOI2023 提高组] 游戏
Problem Description
You are playing a game on a tree.
You are given a tree with nodes and queries. For each query, you are given , and you need to find three nodes such that , , and . Here, denotes the number of edges on the unique simple path between nodes and in the tree, and .
It is guaranteed that a solution exists.
Input Format
The first line contains an integer , the number of nodes in the tree.
The next lines each contain two nodes , representing an edge between and .
The next line contains an integer , the number of queries.
The next lines each contain three integers , representing one query.
Output Format
Output lines. Each line should contain three integers such that , , and . If there are multiple valid triples , output any one of them. It is guaranteed that a solution exists.
10
7 10
2 8
10 2
8 1
9 7
4 5
1 6
9 4
4 3
10
3 2 1
5 4 1
6 6 0
3 0 3
1 5 4
2 5 7
6 5 1
2 1 3
2 0 2
2 2 0
2 6 1
7 6 1
9 6 6
6 2 6
6 1 7
8 6 4
9 6 1
1 2 6
6 8 6
8 6 6
Hint
For of the testdata, .
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For another of the testdata, the -th edge connects and .
For another of the testdata, .
For of the testdata, and .
A checker and checker.exe are provided, for checking answers on 64-bit Linux and Windows, respectively.
You can use ./checker < input file name > < output file name > < answer file name > to check whether your output file is valid.
In fact, the provided checker will not use the answer file, so you can choose any file as the answer file.
You need to ensure that the input file is valid, meaning the format is correct and a solution exists. Otherwise, unknown errors may occur.
Depending on the problems in your output file, the checker will return the following messages:
- If your output file is correct, the checker will return
Accepted!. - If the answer is wrong on test , the checker will return
Wrong answer on test t!. - If your format is incorrect, the checker will return
wrong output formatfollowed by related error information.
UPD: On Luogu, chk.cpp is provided.
Translated by ChatGPT 5