AT_abc456_e.Endless Holidays

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

The Kingdom of AtCoder has NN cities, called city 1,2,…,N1,2,\dots,N. There are MM bidirectional roads connecting pairs of cities, where the ii-th road connects cities UiU_i and ViV_i. Any pair of cities can be reached from each other by traversing some roads.

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

Each city has certain days of the week that are holidays. The holiday information for city ii is given as a string SiS_i of length WW: if the jj-th character of SiS_i is o, day jj is a holiday; if it is x, day jj is a weekday.

Takahashi chooses a city he likes and visits it at noon on day 11. 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.

TT test cases are given; solve each of them.

AtCoder 王国有 NN 座城市,编号为城市 1,2,…,N1,2,\dots,N。有 MM 条双向道路连接若干对城市,其中第 ii 条道路连接城市 UiU_i 和 ViV_i。任意两座城市之间均可通过若干条道路相互到达。

在 AtCoder 王国中,一周包含 WW 天。一周按天数 1,2,…,W1,2,\dots,W 顺序进行,第 WW 天之后是第 11 天。

每座城市都有某些星期几被设为假日。城市 ii 的假日信息以一个长度为 WW 的字符串 SiS_i 给出:若 SiS_i 的第 jj 个字符为 o,则第 jj 天为假日;若为 x,则为工作日。

高桥选择一座他喜欢的城市,并于第 11 天中午抵达该城市。此后每个夜晚,他重复执行如下操作:要么留在当前城市,要么沿一条道路移动至一个相邻城市。若存在一种移动方式,使得他在每天中午所处的城市均为当日的假日,则输出 Yes;否则输出 No。

共给出 TT 组测试数据,请对每组数据求解。

输入格式

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

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

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

NN MM
U1U_1 V1V_1
U2U_2 V2V_2
⋮\vdots
UMU_M VMV_M
WW
S1S_1
S2S_2
⋮\vdots
SNS_N

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

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

其中,casei\mathrm{case}_i 表示第 ii 个测试用例的输入。每个测试用例按以下格式给出:

NN MM
U1U_1 V1V_1
U2U_2 V2V_2
⋮\vdots
UMU_M VMV_M
WW
S1S_1
S2S_2
⋮\vdots
SNS_N

输出格式

Output TT lines. The ii-th line should contain the answer for the ii-th test case.

输出 TT 行。第 ii 行应包含第 ii 个测试用例的答案。

输入输出样例

  • 输入#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

    输出#1

    Yes
    Yes
    No

说明/提示

Sample 1 Explanation:
For the first test case, for example, the condition can be satisfied by repeatedly moving along cities 4→2→1→4→2→1→⋯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→2→3→3→2→3→⋯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 11 indefinitely.

For the third test case, it is impossible to keep moving while satisfying the condition.

Constraints

  • 1≤T≤1051 \leq T \leq 10^5
  • 1≤N≤1051 \leq N \leq 10^5
  • N−1≤M≤105N-1 \leq M \leq 10^5
  • 1≤Ui<Vi≤N1 \leq U_i \lt V_i \leq N
  • Any pair of cities can be reached from each other by traversing some roads.
  • 2≤W≤102 \leq W \leq 10
  • T,N,M,Ui,Vi,WT,N,M,U_i,V_i,W are integers.
  • SiS_i is a string of length WW consisting of o, x.
  • The sum of NN over all test cases is at most 10510^5.
  • The sum of MM over all test cases is at most 10510^5.

样例 1 解释:
对于第一个测试用例,例如,可通过反复沿城市序列 4→2→1→4→2→1→⋯4 \to 2 \to 1 \to 4 \to 2 \to 1 \to \cdots 移动来满足条件。或者,也可通过反复沿城市序列 3→2→3→3→2→3→⋯3 \to 2 \to 3 \to 3 \to 2 \to 3 \to \cdots 移动来满足条件。

对于第二个测试用例,可通过无限期停留在城市 11 来满足条件。

对于第三个测试用例,无法在持续移动的同时满足条件。

约束条件

  • 1≤T≤1051 \leq T \leq 10^5
  • 1≤N≤1051 \leq N \leq 10^5
  • N−1≤M≤105N-1 \leq M \leq 10^5
  • 1≤Ui<Vi≤N1 \leq U_i \lt V_i \leq N
  • 任意两个城市之间均存在一条道路路径(即图连通)。
  • 2≤W≤102 \leq W \leq 10
  • T,N,M,Ui,Vi,WT,N,M,U_i,V_i,W 均为整数。
  • SiS_i 是一个长度为 WW 的字符串,仅由字符 o 和 x 组成。
  • 所有测试用例的 NN 之和不超过 10510^5。
  • 所有测试用例的 MM 之和不超过 10510^5。

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

首页