AtCoder Beginner Contest 456(Promotion of AtCoder Career Design DAY)
E
无尽假期
Endless Holidays
AtCoder
⌀ 1214
原题
←F →

无尽假期AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

The Kingdom of AtCoder has $N$ cities, called city $1,2,\dots,N$. There are $M$ bidirectional roads connecting pairs of cities, where the $i$-th road connects cities $U_i$ and $V_i$. Any pair of cities can be reached from each other by traversing some roads.

AtCoder 王国有 $N$ 座城市,编号为 $1,2,\dots,N$。有 $M$ 条双向道路连接着成对的城市,其中第 $i$ 条道路连接城市 $U_i$ 和 $V_i$。任意两个城市之间都可以通过若干条道路相互到达。AI (CI翻译)

In the Kingdom of AtCoder, a week consists of $W$ days. A week proceeds through days $1,2,\dots,W$, and the day after day $W$ is day $1$.

在 AtCoder 王国中,一周由 $W$ 天组成。一周依次经过第 $1,2,\dots,W$ 天,第 $W$ 天之后是第 $1$ 天。AI (CI翻译)

Each city has certain days of the week that are holidays. The holiday information for city $i$ is given as a string $S_i$ of length $W$: if the $j$-th character of $S_i$ is o, day $j$ is a holiday; if it is x, day $j$ is a weekday.

每座城市都有一周中的若干天是假日。城市 $i$ 的假日信息由一个长度为 $W$ 的字符串 $S_i$ 给出:如果 $S_i$ 的第 $j$ 个字符是 o,则第 $j$ 天是假日;如果是 x,则第 $j$ 天是工作日。AI (CI翻译)

Takahashi chooses a city he likes and visits it at noon on day $1$. Each night thereafter, he repeatedly chooses to either stay in his current city or move to a city directly connected by a road. Output Yes if it is possible for him to keep moving so that the city he is in at noon every day is a holiday, and No otherwise.

高桥选择一座他喜欢的城市,并在第 $1$ 天的中午到达那里。此后,每天晚上他都会选择留在当前城市,或移动到一座通过道路直接连接的城市。请判断他是否能够持续移动,使得自己每天中午所在的城市都是假日城市。如果可以,输出 Yes;否则输出 No。AI (CI翻译)

$T$ test cases are given; solve each of them.

给出 $T$ 组测试用例,请分别求出每组的答案。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \leq T \leq 10^5$
  • $1 \leq N \leq 10^5$
  • $N-1 \leq M \leq 10^5$
  • $1 \leq U_i \lt V_i \leq N$
  • Any pair of cities can be reached from each other by traversing some roads.
  • $2 \leq W \leq 10$
  • $T,N,M,U_i,V_i,W$ are integers.
  • $S_i$ is a string of length $W$ consisting of o, x.
  • The sum of $N$ over all test cases is at most $10^5$.
  • The sum of $M$ over all test cases is at most $10^5$.
  • $1 \leq T \leq 10^5$
  • $1 \leq N \leq 10^5$
  • $N-1 \leq M \leq 10^5$
  • $1 \leq U_i \lt V_i \leq N$
  • 任意两个城市之间都可以通过若干条道路相互到达。
  • $2 \leq W \leq 10$
  • $T,N,M,U_i,V_i,W$ 均为整数。
  • $S_i$ 是一个由 o、x 组成的长度为 $W$ 的字符串。
  • 所有测试用例的 $N$ 之和不超过 $10^5$。
  • 所有测试用例的 $M$ 之和不超过 $10^5$。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

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

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
AI (CI翻译)

Here, $\mathrm{case}_i$ denotes the input for the $i$-th test case. Each test case is given in the following format:

其中,$\mathrm{case}_i$ 表示第 $i$ 组测试用例的输入。每组测试用例的输入格式如下:AI (CI翻译)

N M
U_1 V_1
U_2 V_2
\vdots
U_M V_M
W
S_1
S_2
\vdots
S_N

N M
U_1 V_1
U_2 V_2
\vdots
U_M V_M
W
S_1
S_2
\vdots
S_N
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $T$ lines. The $i$-th line should contain the answer for the $i$-th test case.

输出 $T$ 行。第 $i$ 行应包含第 $i$ 组测试用例的答案。AI (CI翻译)

样例

Input #1
3
4 4
1 2
1 4
2 4
2 3
3
xxo
xox
oxo
oxx
1 0
4
oooo
5 5
1 4
2 3
4 5
3 4
2 5
7
oxxxxxx
xxoxxxo
xxxoxox
xoxxoxx
oxxxoxx
Output #1
Yes
Yes
No
For the first test case, for example, the condition can be satisfied by repeatedly moving along cities $4 \to 2 \to 1 \to 4 \to 2 \to 1 \to \cdots$. Alternatively, the condition can also be satisfied by repeatedly moving along cities $3 \to 2 \to 3 \to 3 \to 2 \to 3 \to \cdots$. For the second test case, the condition can be satisfied by staying in city $1$ indefinitely. For the third test case, it is impossible to keep moving while satisfying the condition.
题目信息
题号
abc456_e
时间限制
3 s
内存限制
1024 MB

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