AT_ndpc2026_t.Independent Set
入门
通过率:0%
时间限制:10.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a tree with N vertices, numbered from 1 to N. The i-th edge connects vertices ui and vi.
A set of vertices S is called an independent set if it satisfies the following condition:
- For any two distinct vertices u,v∈S, u and v are not adjacent in the tree.
For a vertex v, let Fv be the set of all independent sets S such that v∈S.
You are given Q queries. In each query, you are given an integer v (1≤v≤N) and an integer q. Compute:
(S∈Fv∑q∣S∣)mod998244353
Here, ∣S∣ denotes the size of the set S.
给你一棵包含 N 个顶点的树,顶点编号为 1 到 N。第 i 条边连接顶点 ui 和 vi。
顶点集合 S 被称为独立集,当且仅当它满足以下条件:
- 对任意两个互异的顶点 u,v∈S,u 与 v 在树中不相邻。
对任一顶点 v,记 Fv 为所有满足 v∈S 的独立集 S 构成的集合。
你将收到 Q 个查询。对每个查询,给定一个整数 v(1≤v≤N)和一个整数 q,请计算:
(S∈Fv∑q∣S∣)mod998244353
其中,∣S∣ 表示集合 S 的大小。
输入格式
The input is given from standard input in the following format:
N Q
u1 v1
u2 v2
⋮
uN−1 vN−1
query1
query2
⋮
queryQ
Each query is given in the following format:
v q
输入从标准输入中按以下格式给出:
N Q
u1 v1
u2 v2
⋮
uN−1 vN−1
query1
query2
⋮
queryQ
每个查询按以下格式给出:
v q
输出格式
Print Q lines. On the i-th line, output the answer to the i-th query.
输出 Q 行。第 i 行输出第 i 个查询的答案。
输入输出样例
输入#1
4 2 1 2 1 3 2 4 1 1 2 3
输出#1
2 12
输入#2
10 10 1 2 2 3 1 4 1 5 1 6 6 7 6 8 5 9 1 10 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10
输出#2
16 162 768 2500 6480 14406 28672 52488 90000 146410
输入#3
10 10 1 2 1 3 2 4 4 5 4 6 2 7 5 8 8 9 6 10 5 844033520 8 780395612 2 285523486 6 13801767 3 487663185 3 667406485 7 672229269 7 207478896 5 769551740 7 806405364
输出#3
665599367 675643489 193550820 987507475 230555342 555586355 204648376 83113599 299301383 545057926
说明/提示
Partial Score
This problem has partial scoring.
- If all queries satisfy v=1, you will get 5 points.
Sample 1 Explanation:
Consider the first query. The independent sets that contain vertex 1 are 1 and 1,4, so there are 2 such sets. Therefore, output 11+12=2.
Constraints
- 2≤N≤1.3×105
- 1≤Q≤1.3×105
- 1≤ui<vi≤N
- The given graph is a tree
- 1≤v≤N
- 1≤q<998244353
- All input values are integers
部分得分
本题采用部分得分制。
- 若所有查询均满足 v=1,则可获得 5 分。
样例 1 解释:
考虑第一个查询。包含顶点 1 的独立集有 {1} 和 {1,4},共 2 个。因此输出 11+12=2。
约束条件
- 2≤N≤1.3×105
- 1≤Q≤1.3×105
- 1≤ui<vi≤N
- 给定图是一棵树
- 1≤v≤N
- 1≤q<998244353
- 所有输入值均为整数
输入解题思路,AI测评打分。不知道怎么写?