AT_abc456_e.Endless Holidays
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The Kingdom of AtCoder has N cities, called city 1,2,…,N. There are M bidirectional roads connecting pairs of cities, where the i-th road connects cities Ui and Vi. Any pair of cities can be reached from each other by traversing some roads.
In the Kingdom of AtCoder, a week consists of W days. A week proceeds through days 1,2,…,W, and the day after day W is day 1.
Each city has certain days of the week that are holidays. The holiday information for city i is given as a string Si of length W: if the j-th character of Si is o, day j is a holiday; if it is x, day j is a weekday.
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.
T test cases are given; solve each of them.
AtCoder 王国有 N 座城市,编号为城市 1,2,…,N。有 M 条双向道路连接若干对城市,其中第 i 条道路连接城市 Ui 和 Vi。任意两座城市之间均可通过若干条道路相互到达。
在 AtCoder 王国中,一周包含 W 天。一周按天数 1,2,…,W 顺序进行,第 W 天之后是第 1 天。
每座城市都有某些星期几被设为假日。城市 i 的假日信息以一个长度为 W 的字符串 Si 给出:若 Si 的第 j 个字符为 o,则第 j 天为假日;若为 x,则为工作日。
高桥选择一座他喜欢的城市,并于第 1 天中午抵达该城市。此后每个夜晚,他重复执行如下操作:要么留在当前城市,要么沿一条道路移动至一个相邻城市。若存在一种移动方式,使得他在每天中午所处的城市均为当日的假日,则输出 Yes;否则输出 No。
共给出 T 组测试数据,请对每组数据求解。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Here, casei denotes the input for the i-th test case. Each test case is given in the following format:
N M
U1 V1
U2 V2
⋮
UM VM
W
S1
S2
⋮
SN
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
其中,casei 表示第 i 个测试用例的输入。每个测试用例按以下格式给出:
N M
U1 V1
U2 V2
⋮
UM VM
W
S1
S2
⋮
SN
输出格式
Output T lines. The i-th line should contain the answer for the i-th test case.
输出 T 行。第 i 行应包含第 i 个测试用例的答案。
输入输出样例
输入#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→⋯. Alternatively, the condition can also be satisfied by repeatedly moving along cities 3→2→3→3→2→3→⋯.
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.
Constraints
- 1≤T≤105
- 1≤N≤105
- N−1≤M≤105
- 1≤Ui<Vi≤N
- Any pair of cities can be reached from each other by traversing some roads.
- 2≤W≤10
- T,N,M,Ui,Vi,W are integers.
- Si is a string of length W consisting of
o,x. - The sum of N over all test cases is at most 105.
- The sum of M over all test cases is at most 105.
样例 1 解释:
对于第一个测试用例,例如,可通过反复沿城市序列 4→2→1→4→2→1→⋯ 移动来满足条件。或者,也可通过反复沿城市序列 3→2→3→3→2→3→⋯ 移动来满足条件。
对于第二个测试用例,可通过无限期停留在城市 1 来满足条件。
对于第三个测试用例,无法在持续移动的同时满足条件。
约束条件
- 1≤T≤105
- 1≤N≤105
- N−1≤M≤105
- 1≤Ui<Vi≤N
- 任意两个城市之间均存在一条道路路径(即图连通)。
- 2≤W≤10
- T,N,M,Ui,Vi,W 均为整数。
- Si 是一个长度为 W 的字符串,仅由字符
o和x组成。 - 所有测试用例的 N 之和不超过 105。
- 所有测试用例的 M 之和不超过 105。
输入解题思路,AI测评打分。不知道怎么写?