A9585 | Strongly Connected City
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
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.
输出格式
If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted