第 76 场 AtCoder Grand Contest
C
史莱姆吃史莱姆
Slime Eat Slime
AtCoder
⌀ 3572
原题
← BD →

史莱姆吃史莱姆AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

There are $N$ slimes numbered from $1$ to $N$. The color of each slime is represented by an integer between $0$ and $2K$ (inclusive), and the color of slime $i$ is $C_i$.

有 $N$ 个编号为 $1$ 至 $N$ 的史莱姆。每个史莱姆的颜色由一个介于 $0$ 和 $2K$(含)之间的整数表示,史莱姆 $i$ 的颜色为 $C_i$。AI (CI翻译)

Currently, $M$ pairs of slimes are in a (bidirectional) friendship. Specifically, slimes $A_i$ and $B_i$ are friends ($1 \leq i \leq M$). Here, it is guaranteed that for any two slimes, one can reach the other by following friendship relations.

目前有 $M$ 对史莱姆处于(双向)友谊关系中。具体来说,史莱姆 $A_i$ 和 $B_i$ 是朋友($1 \leq i \leq M$)。保证对于任意两个史莱姆,都可以通过沿着友谊关系从一个到达另一个。AI (CI翻译)

You can perform the following operation:

你可以进行以下操作:AI (CI翻译)

  • First, choose a pair of slimes $(u,v)$ that satisfies both of the following conditions:
  • Slimes $u$ and $v$ are in a friendship.
    • $(C_u - C_v) \bmod (2K+1) \geq K+1$ (here, the result of $x \bmod y$ is always in the range $[0,y-1]$).
  • Then, let slime $u$ eat slime $v$. Slime $v$ disappears from the field. Also, all slimes except $u$ that were in a friendship with slime $v$ become friends with slime $u$ (if they were already friends with slime $u$, nothing happens).
  • 首先,选择一对满足以下所有条件的史莱姆 $(u,v)$:
  • 史莱姆 $u$ 和 $v$ 是朋友。
    • $(C_u - C_v) \bmod (2K+1) \geq K+1$(这里,$x \bmod y$ 的结果始终在 $[0,y-1]$ 范围内)。
  • 然后,让史莱姆 $u$ 吃掉史莱姆 $v$。史莱姆 $v$ 会从场上消失。此外,除 $u$ 以外,所有原本与史莱姆 $v$ 是朋友的史莱姆都会与史莱姆 $u$ 成为朋友(如果它们原本已经与史莱姆 $u$ 是朋友,则不发生任何变化)。
AI (CI翻译)

Determine whether it is possible to leave only slime $1$ on the field by repeating the operation appropriately.

请判断是否可以通过适当地重复进行操作,使场上只剩下史莱姆 $1$。AI (CI翻译)

Solve $T$ cases for one input.

对于一个输入,解决 $T$ 个测试用例。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \leq T \leq 125000$
  • $2 \leq N \leq 250000$
  • $N-1 \leq M \leq 250000$
  • $1 \leq K \leq N$
  • $0 \leq C_i \leq 2K$
  • $1 \leq A_i < B_i \leq N$
  • $(A_i,B_i) \neq (A_j,B_j)$ ($i \neq j$)
  • For any two slimes, one can reach the other by following friendship relations.
  • The sum of $N$ over the $T$ cases is at most $250000$.
  • The sum of $M$ over the $T$ cases is at most $250000$.
  • All input values are integers.
  • $1 \leq T \leq 125000$
  • $2 \leq N \leq 250000$
  • $N-1 \leq M \leq 250000$
  • $1 \leq K \leq N$
  • $0 \leq C_i \leq 2K$
  • $1 \leq A_i < B_i \leq N$
  • $(A_i,B_i) \neq (A_j,B_j)$($i \neq j$)
  • 对于任意两个史莱姆,都可以通过沿着友谊关系从一个到达另一个。
  • 所有测试用例的 $N$ 之和不超过 $250000$。
  • 所有测试用例的 $M$ 之和不超过 $250000$。
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

输入从标准输入给出,格式如下:AI (CI翻译)

T
case_1
case_2
\vdots
case_T

T
case_1
case_2
\vdots
case_T
AI (CI翻译)

Each test case is given in the following format:

每个测试用例的格式如下:AI (CI翻译)

N M K
C_1 C_2 \cdots C_N
A_1 B_1
A_2 B_2
\vdots
A_M B_M

N M K
C_1 C_2 \cdots C_N
A_1 B_1
A_2 B_2
\vdots
A_M B_M
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $T$ lines. The $i$-th line should contain Yes if it is possible to leave only slime $1$ on the field for the $i$-th case, and No otherwise.

输出 $T$ 行。第 $i$ 行中,如果对于第 $i$ 个测试用例,可以使场上只剩下史莱姆 $1$,则输出 Yes;否则输出 No。AI (CI翻译)

样例

Input #1
4
2 1 1
0 0
1 2
3 2 1
0 2 1
1 2
2 3
6 6 1
0 0 1 2 1 0
1 2
2 3
3 4
4 5
5 6
1 6
5 4 2
2 4 3 2 1
1 2
2 4
2 5
3 5
Output #1
No
Yes
No
No
In the first test case, no operation can be performed. In the second test case, it is possible to leave only slime $1$ on the field by the following procedure: - Choose $(u,v)=(3,2)$ and let slime $3$ eat slime $2$. Slime $2$ disappears, and slimes $1$ and $3$ become friends. - Choose $(u,v)=(1,3)$ and let slime $1$ eat slime $3$. Slime $3$ disappears.
题目信息
题号
agc076_c
时间限制
3 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。