CF475B.Strongly Connected City
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Imagine a city with n horizontal streets crossing m vertical streets, forming an (n - 1) × (m - 1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.

The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.
想象一座城市,其中有 n 条水平街道与 m 条垂直街道相交,构成一个 (n − 1) × (m − 1) 的网格。为提升交通流量,该市市长决定将每条街道设为单行道。这意味着:每条水平街道上的车流方向只能是自西向东,或只能是自东向西;每条垂直街道上的车流方向只能是自北向南,或只能是自南向北。车辆可在水平街道与垂直街道的交叉口处,从一条街道驶入另一条街道。

市长已收到若干种街道定向方案。你的任务是:判断在所给定的街道定向方案下,是否能从任意一个路口到达其他任意一个路口。
输入格式
The first line of input contains two integers n and m, (2 ≤ n, m ≤ 20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length n, made of characters '<' and '>', denoting direction of each horizontal street. If the i-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.
The third line contains a string of length m, made of characters '^' and 'v', denoting direction of each vertical street. If the i-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.
输入的第一行包含两个整数 n 和 m(2 ≤ n, m ≤ 20),分别表示水平街道的数量和垂直街道的数量。
第二行包含一个长度为 n 的字符串,由字符 < 和 > 组成,表示每条水平街道的方向。若第 i 个字符为 <,则该街道方向为自东向西;否则(即为 >),该街道方向为自西向东。街道按从北到南的顺序列出。
第三行包含一个长度为 m 的字符串,由字符 ^ 和 v 组成,表示每条垂直街道的方向。若第 i 个字符为 ^,则该街道方向为自南向北;否则(即为 v),该街道方向为自北向南。街道按从西到东的顺序列出。
输出格式
If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".
如果给定的图案满足市长的标准,则输出一行“YES”;否则输出一行“NO”。
输入输出样例
输入#1
3 3 ><> v^v
输出#1
NO
输入#2
4 6 <><> v^v^v^
输出#2
YES
说明/提示
The figure above shows street directions in the second sample test case.
上图展示了第二个样例测试用例中的街道方向。
输入解题思路,AI测评打分。不知道怎么写?