AT_scpc2026_div1_l.Lulu, the Magician

入门

通过率:0%

时间限制:5.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Lulu is actually a genius magician. After a long period of research, Lulu developed a secret magic of her own using a magic circle.

The magic circle Lulu uses is a tree structure consisting of NN spells and N−1N-1 connections. The spells are numbered in order from 11 to NN, and Lulu can strengthen each spell. The ii-th connection of the magic circle means that spell aia_i and spell bib_i are directly connected.

Initially, the power of every spell is 00. When Lulu strengthens spell rr by ww, the power WrW_r of spell rr increases by ww.

Lulu can cast magic by choosing two spells uu and vv in the magic circle. When Lulu casts magic, every spell in the magic circle interacts with the set P(u,v)P(u,v) of vertices on the unique simple path connecting uu and vv. The final power of the magic Lulu casts can be calculated by the following formula. Here, d(a,b)d(a,b) is the number of edges on the unique simple path connecting aa and bb.

∑x∈P(u,v)∑r=1NWr×d(r,x)\sum_{x \in P(u, v)} \sum_{r=1}^{N} W_r \times d(r, x)

The genius magician Lulu wants to learn magic by performing the following two types of actions in order, QQ times in total.

  • 1 v w: Increase the power of spell vv by ww.

  • 2 u v: Choose spells uu and vv and cast magic.

For each action of type 22, compute the final power of the cast magic modulo 998 244 353998\,244\,353.

露露实际上是一位天才魔法师。经过长期研究,露露利用一个魔法阵,开发出了属于自己的秘密魔法。

露露所使用的魔法阵是一个由 NN 个咒语和 N−1N-1 条连接构成的树形结构。这些咒语按顺序编号为 11 至 NN,露露可以强化其中任意一个咒语。第 ii 条连接表示咒语 aia_i 与咒语 bib_i 直接相连。

初始时,每个咒语的力量值均为 00。当露露将咒语 rr 强化 ww 单位时,咒语 rr 的力量值 WrW_r 增加 ww。

露露可通过在魔法阵中选择两个咒语 uu 和 vv 来施放魔法。施放魔法时,魔法阵中的每个咒语都会与连接 uu 和 vv 的唯一简单路径上的顶点集合 P(u,v)P(u,v) 发生交互。露露所施放魔法的最终威力可由以下公式计算。其中,d(a,b)d(a,b) 表示连接 aa 和 bb 的唯一简单路径上的边数。

∑x∈P(u,v)∑r=1NWr×d(r,x)\sum_{x \in P(u, v)} \sum_{r=1}^{N} W_r \times d(r, x)

这位天才魔法师露露希望通过依次执行以下两种操作共 QQ 次来学习魔法:

  • 1 v w:将咒语 vv 的力量值增加 ww;

  • 2 u v:选择咒语 uu 和 vv 并施放魔法。

对每一次类型为 2 的操作,请计算所施放魔法的最终威力,并对 998 244 353998\,244\,353 取模。

输入格式

The input is given from Standard Input in the following format:

NN QQ
a1a_1 b1b_1
a2a_2 b2b_2
⋮\vdots
aN−1a_{N-1} bN−1b_{N-1}
action1\mathrm{action}_1
action2\mathrm{action}_2
⋮\vdots
actionQ\mathrm{action}_Q

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

NN QQ
a1a_1 b1b_1
a2a_2 b2b_2
⋮\vdots
aN−1a_{N-1} bN−1b_{N-1}
action1\mathrm{action}_1
action2\mathrm{action}_2
⋮\vdots
actionQ\mathrm{action}_Q

输出格式

For each action of type 22, output one line containing the final power of the cast magic modulo 998 244 353998\,244\,353.

对于每个类型为 22 的操作,输出一行,包含施放魔法的最终力量值对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    4 3
    1 2
    2 3
    3 4
    1 2 5
    1 4 3
    2 1 4

    输出#1

    38

说明/提示

表示言語

/ /

Constraints

  • 1≤N,Q≤200 0001 \leq N, Q \leq 200\,000
  • 1≤ai,bi≤N1 \leq a_i, b_i \leq N
  • ai≠bia_i \ne b_i
  • The given magic circle is a tree.
  • In an action of the form 1 v w, 1≤v≤N1 \leq v \leq N and 1≤w≤1091 \leq w \leq 10^9.
  • In an action of the form 2 u v, 1≤u,v≤N1 \leq u, v \leq N.
  • All given numbers are integers.

表示语言

/ /

约束条件

  • 1≤N,Q≤200 0001 \leq N, Q \leq 200\,000
  • 1≤ai,bi≤N1 \leq a_i, b_i \leq N
  • ai≠bia_i \ne b_i
  • 给定的魔法环是一棵树。
  • 对于形如 1 v w 的操作,满足 1≤v≤N1 \leq v \leq N 且 1≤w≤1091 \leq w \leq 10^9。
  • 对于形如 2 u v 的操作,满足 1≤u,v≤N1 \leq u, v \leq N。
  • 所有给定的数均为整数。

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

首页