Bayan 2015 Contest Warm Up
B
Strongly Connected City
Codeforces
1400
原题
← AC →
翻译中…

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.

翻译中…

image

翻译中…

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.

翻译中…

Input

翻译中…

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.

翻译中…

Output

翻译中…

If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".

翻译中…

Note

翻译中…

The figure above shows street directions in the second sample test case.

翻译中…

样例

Input #1
3 3
><>
v^v
Output #1
NO
InputCopy OutputCopy
Input #2
4 6
<><>
v^v^v^
Output #2
YES
InputCopy OutputCopy
题目信息
题号
475B
时间限制
2 s
内存限制
256 MB
标签
暴力
DFS 及类似
图论
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。