AT_ndpc2026_t.Independent Set

入门

通过率:0%

时间限制:10.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a tree with NN vertices, numbered from 11 to NN. The ii-th edge connects vertices uiu_i and viv_i.

A set of vertices SS is called an independent set if it satisfies the following condition:

  • For any two distinct vertices u,v∈Su, v \in S, uu and vv are not adjacent in the tree.

For a vertex vv, let FvF_v be the set of all independent sets SS such that v∈Sv \in S.

You are given QQ queries. In each query, you are given an integer vv (1≤v≤N1 \leq v \leq N) and an integer qq. Compute:

(∑S∈Fvq∣S∣) mod 998244353\displaystyle \left( \sum_{S \in F_v} q^{|S|}\right) \bmod 998244353

Here, ∣S∣|S| denotes the size of the set SS.

给你一棵包含 NN 个顶点的树,顶点编号为 11 到 NN。第 ii 条边连接顶点 uiu_i 和 viv_i。

顶点集合 SS 被称为独立集,当且仅当它满足以下条件:

  • 对任意两个互异的顶点 u,v∈Su, v \in S,uu 与 vv 在树中不相邻。

对任一顶点 vv,记 FvF_v 为所有满足 v∈Sv \in S 的独立集 SS 构成的集合。

你将收到 QQ 个查询。对每个查询,给定一个整数 vv(1≤v≤N1 \leq v \leq N)和一个整数 qq,请计算:

(∑S∈Fvq∣S∣) mod 998244353\displaystyle \left( \sum_{S \in F_v} q^{|S|}\right) \bmod 998244353

其中,∣S∣|S| 表示集合 SS 的大小。

输入格式

The input is given from standard input in the following format:

NN QQ
u1u_1 v1v_1
u2u_2 v2v_2
⋮\vdots
uN−1u_{N-1} vN−1v_{N-1}
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

Each query is given in the following format:

vv qq

输入从标准输入中按以下格式给出:

NN QQ
u1u_1 v1v_1
u2u_2 v2v_2
⋮\vdots
uN−1u_{N-1} vN−1v_{N-1}
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

每个查询按以下格式给出:

vv qq

输出格式

Print QQ lines. On the ii-th line, output the answer to the ii-th query.

输出 QQ 行。第 ii 行输出第 ii 个查询的答案。

输入输出样例

  • 输入#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=1v=1, you will get 55 points.

Sample 1 Explanation:
Consider the first query. The independent sets that contain vertex 11 are 1{1} and 1,4{1, 4}, so there are 22 such sets. Therefore, output 11+12=21^1 + 1^2 = 2.

Constraints

  • 2≤N≤1.3×1052 \leq N \leq 1.3 \times 10^5
  • 1≤Q≤1.3×1051 \leq Q \leq 1.3 \times 10^5
  • 1≤ui<vi≤N1 \leq u_i < v_i \leq N
  • The given graph is a tree
  • 1≤v≤N1 \leq v \leq N
  • 1≤q<9982443531 \leq q < 998244353
  • All input values are integers

部分得分

本题采用部分得分制。

  • 若所有查询均满足 v=1v=1,则可获得 55 分。

样例 1 解释:
考虑第一个查询。包含顶点 11 的独立集有 {1}\{1\} 和 {1,4}\{1, 4\},共 22 个。因此输出 11+12=21^1 + 1^2 = 2。

约束条件

  • 2≤N≤1.3×1052 \leq N \leq 1.3 \times 10^5
  • 1≤Q≤1.3×1051 \leq Q \leq 1.3 \times 10^5
  • 1≤ui<vi≤N1 \leq u_i < v_i \leq N
  • 给定图是一棵树
  • 1≤v≤N1 \leq v \leq N
  • 1≤q<9982443531 \leq q < 998244353
  • 所有输入值均为整数

输入解题思路,AI测评打分。不知道怎么写?

首页