AT_scpc2026_div1_i.Tree, Game, and Query

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Terra and Lulu are playing a board game on a tree consisting of NN vertices and N−1N-1 edges. Each vertex ii of the tree has a weight ViV_i and a multiplier WiW_i. The ii-th edge of the tree connects vertices uiu_i and viv_i. Initially, all multipliers WiW_i are 11, and vertex 11 is the root.

When a game starts, all stones currently on each vertex ii are removed, and Vi⋅WiV_i \cdot W_i stones are placed on that vertex. The players take turns performing the following action.

  1. Choose a non-root vertex with at least 11 stone on it.

  2. Choose one or more stones on the chosen vertex and move them to its parent vertex.

The player who can no longer perform an action loses, and the other player wins. Each game starts with Terra.

Terra and Lulu are so good at the game that they found it monotonous. They decided to play QQ games while performing the following two types of queries in order.

  • 1 x y: For every vertex ii on the shortest path between vertices xx and yy, change its multiplier WiW_i to 1−Wi1 - W_i. In other words, 00 changes to 11, and 11 changes to 00.

  • 2 z: Change the root of the tree to vertex zz. If vertex zz is already the root of the tree, nothing happens.

Each time a query is performed, Terra and Lulu start a new game from the beginning. For each of the QQ games, determine who wins if both players play optimally. The effects of all queries are cumulative.

特拉(Terra)和露露(Lulu)正在一棵包含 NN 个顶点和 N−1N-1 条边的树上玩一个棋盘游戏。树中每个顶点 ii 具有权重 ViV_i 和乘数 WiW_i。树的第 ii 条边连接顶点 uiu_i 和 viv_i。初始时,所有乘数 WiW_i 均为 11,且顶点 11 为根节点。

游戏开始时,将每个顶点 ii 上当前所有的石子全部移除,并在该顶点上放置 Vi⋅WiV_i \cdot W_i 颗石子。双方轮流执行以下操作:

  1. 选择一个非根顶点,且其上至少有 11 颗石子;

  2. 从所选顶点上选择一颗或多颗石子,并将它们移动至其父顶点。

无法再执行操作的玩家判负,另一方获胜。每局游戏均由特拉先手。

特拉与露露棋艺高超,以至于觉得此游戏单调乏味。于是她们决定进行 QQ 局游戏,并按顺序执行以下两类查询:

  • 1 x y:对顶点 xx 与 yy 之间最短路径上的每一个顶点 ii,将其乘数 WiW_i 更新为 1−Wi1 - W_i。换言之,00 变为 11,11 变为 00。

  • 2 z:将树的根节点更改为顶点 zz。若顶点 zz 当前已是根节点,则不执行任何操作。

每次查询执行后,特拉与露露均从头开始一局新游戏。对于这 QQ 局游戏中的每一局,请判断:若双方均以最优策略进行游戏,谁将获胜?所有查询的影响是累积的。

输入格式

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

NN QQ
V1V_1 V2V_2 …\dots VNV_N
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 one of the following two formats.

1 x y

2 z

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

NN QQ
V1V_1 V2V_2 …\dots VNV_N
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

每个查询以以下两种格式之一给出:

1 x y

2 z

输出格式

For each game played after a query, output Terra if Terra wins, and Lulu if Lulu wins, one per line.

对于每次查询之后进行的比赛,若 Terra 获胜则输出 Terra,若 Lulu 获胜则输出 Lulu,每行一个。

输入输出样例

  • 输入#1

    4 4
    10 1 2 3
    1 2
    1 3
    1 4
    2 1
    1 2 3
    2 2
    1 1 1

    输出#1

    Lulu
    Terra
    Lulu
    Terra

说明/提示

表示言語

/ /

Constraints

  • 2≤N≤300 0002 \leq N \leq 300\,000
  • 1≤Q≤500 0001 \leq Q \leq 500\,000
  • 1≤Vi≤1091 \leq V_i \leq 10^9
  • 1≤ui,vi≤N1 \leq u_i, v_i \leq N
  • 1≤x,y,z≤N1 \leq x, y, z \leq N
  • ui≠viu_i \ne v_i
  • All given numbers are integers.
  • The given graph is a tree.

表示语言

/ /

限制条件

  • 2≤N≤300 0002 \leq N \leq 300\,000
  • 1≤Q≤500 0001 \leq Q \leq 500\,000
  • 1≤Vi≤1091 \leq V_i \leq 10^9
  • 1≤ui,vi≤N1 \leq u_i, v_i \leq N
  • 1≤x,y,z≤N1 \leq x, y, z \leq N
  • ui≠viu_i \ne v_i
  • 所有给定的数均为整数。
  • 给定的图是一棵树。

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

首页