#P3806. 【模板】点分治
【模板】点分治
Description
Given a tree with nodes, determine for each query whether there exists a pair of nodes whose distance on the tree equals .
Input Format
The first line contains two integers .
The next lines, each contains three integers , representing an edge between and with weight .
Then lines follow, each containing one integer , representing a query.
Output Format
For each query, output one line with a string representing the answer. Output AYE if such a pair exists, otherwise output NAY.
2 1
1 2 2
2
AYE
Hint
Constraints
- For of the testdata, is guaranteed.
- For of the testdata, , are guaranteed.
- For of the testdata, , , , , are guaranteed.
Notes
- This problem does not stress constant factors.
- If test point #7 keeps RE/TLE, consider checking this post: https://www.luogu.com.cn/discuss/show/188596.
Translated by ChatGPT 5
京公网安备 11011102002149号