QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#21959. 点分治

統計

题目描述

给定一棵 $n$ 个点的树。

有 $m$ 次询问,每次给定一个 $k$,询问树上长度为 $k$ 的路径是否存在。

输入格式

第一行两个数 $n$, $m$。

第 $2$ 到第 $n$ 行,每行三个整数 $u,v,w$,代表树上存在一条连接 $u$ 和 $v$ 边权为 $w$ 的路径。

接下来 $m$ 行,每行一个整数 $k$,代表一次询问。

输出格式

对于每次询问,若存在输出 Yes,否则输出 No

样例数据

样例 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

样例 1 输出

Yes
Yes
No
No
Yes
No
Yes
Yes
Yes
Yes

子任务

对于 $100\%$ 的数据,$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, 1 \leq w \leq 10^4$

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.