QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#21959. Centroid Decomposition

统计

Given a tree with $n$ nodes.

There are $m$ queries. For each query, you are given an integer $k$, and you need to determine whether there exists a path of length $k$ in the tree.

Input

The first line contains two integers $n$ and $m$.

The next $n-1$ lines each contain three integers $u, v, w$, representing an edge between $u$ and $v$ with weight $w$.

The following $m$ lines each contain an integer $k$, representing a query.

Output

For each query, output Yes if such a path exists, otherwise output No.

Subtasks

For $100\%$ of the data, $1 \leq n \leq 3 \times 10^4$, $1 \leq m \leq 100$, $1 \leq k \leq 10^7$, $1 \leq u, v \leq n$, and $1 \leq w \leq 10^4$.

Examples

Input 1

14 10
2 1 7
3 1 19
4 3 9
5 1 1
6 4 20
7 1 5
8 3 19
9 8 1
10 4 5
11 7 2
12 10 11
13 12 12
14 11 7
6
12
18
22
26
31
35
42
45
53

Output 1

Yes
Yes
No
No
Yes
No
Yes
Yes
Yes
Yes

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.