QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 512 MB Total points: 100

#9636. 签到题

Statistics

题目描述

给出一棵 $n$ 个点 $m$ 条边的仙人掌 $G$,点 $i$ 有点权 $a_i$。(其中仙人掌定义为每条边至多出现在一个简单环中的简单无向连通图)。

$q$ 次询问,每次询问给出 $k$,表示查询在仙人掌上选择一个非空子树(也就是仙人掌的一个无环连通子图)和子树中的一个点 $r$,使得子树中所有点到 $r$ 在选出的子树上的距离之和 $\text{sum}$ 至少为 $k$ 的情况下,子树上所有点的点权的 $\text{gcd}$ 最大是多少。

输入格式

第一行 $4$ 个数 $C, n, m, q$,其中 $C$ 表示子任务编号(样例的 $C = 0$)。

接下来一行 $n$ 个正整数 $a_i$。

接下来 $m$ 行每行两个正整数 $u, v$ 表示 $u$ 和 $v$ 由一条双向边链接。

接下来 $q$ 行每行一个正整数 $k$。

以上字母未经特殊说明均与题目描述中含义一致。

输出格式

输出 $q$​ 行,每行一个数,依次表示对应询问的答案。特别地,如果不存在这样的选择子树方法,输出 -1

样例 1

样例输入 1

0 5 6 1
2 4 6 8 9
1 2
1 3
2 3
2 4
2 5
4 5
5

样例输出 1

2

更多样例见下发文件

数据范围

对于所有数据 $3 \le n \le 2 \times 10^5$,$n - 1 \le m \le \min {2n, 2 \times 10^5}$,$1 \le a_i \le A \le 10^6$,$1 \le u, v \le n$,$1 \le q \le 2 \times 10^5$,$1 \le k \le 10^{10}$,保证输入是一棵仙人掌。

子任务编号 $n$ $m$ $q$ $A$ 子任务依赖 分值
$1$ $\le 5$ $=1$ $=20$ $10$
$2$ $\le 20$ $\le 20$ $=20$ $1$ $10$
$3$ $=n-1$ $20$
$4$ $=n$ $3$ $20$
$5$ $\le 100$ $2$ $20$
$6$ $4,5$ $20$
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.