#P3806. 【模板】点分治

    ID: 2687 远端评测题 200ms 500MiB 尝试: 2 已通过: 1 难度: 7 上传者: 标签>点分治O2优化分治深度优先搜索,DFS

【模板】点分治

Description

Given a tree with nn nodes, determine for each query whether there exists a pair of nodes whose distance on the tree equals kk.

Input Format

The first line contains two integers n,mn, m.

The next n1n-1 lines, each contains three integers u,v,wu, v, w, representing an edge between uu and vv with weight ww.

Then mm lines follow, each containing one integer kk, 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 30%30\% of the testdata, n100n \leq 100 is guaranteed.
  • For 60%60\% of the testdata, n1000n \leq 1000, m50m \leq 50 are guaranteed.
  • For 100%100\% of the testdata, 1n1041 \leq n \leq 10^4, 1m1001 \leq m \leq 100, 1k1071 \leq k \leq 10^7, 1u,vn1 \leq u, v \leq n, 1w1041 \leq w \leq 10^4 are guaranteed.

Notes

Translated by ChatGPT 5