当前位置: 首页 > news >正文

Strongly Connected City

E. Strongly Connected City

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.

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”.

Example

Input

3 3
><>
v^v

Output

NO

Input

4 6
<><>
v^v^v^

Output

YES

Node

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

code

#include<bits/stdc++.h>
#define int long long
#define endl '\n'using namespace std;const int N = 40,INF=0x3f3f3f3f,mod=1e9+7;typedef pair<int,int> PII;int T=1;
char a[3][N];void solve(){int n,m;cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[1][i];}for(int i=1;i<=m;i++) cin>>a[2][i];if((a[1][1]=='<' && a[2][1]=='^') || (a[1][1]=='>' && a[2][m]=='^') || (a[1][n]=='<' && a[2][1]=='v') || (a[1][n]=='>' && a[2][m]=='v')){cout<<"NO"<<endl;return;}cout<<"YES"<<endl;
}signed main(){
//	cin>>T; while(T--){solve();}return 0;
}

http://www.mrgr.cn/news/63158.html

相关文章:

  • 因特网的概述和三种交换方式
  • 使用opencv调用TV_L1算法提取光流
  • 【CTF】 文件包含漏洞——data伪协议 【详】
  • 二叉查找树知识简记
  • ELK之路第三步——日志收集筛选logstash和filebeat
  • urllib库
  • FlinkCDC-MYSQL批量写入
  • 第三百零七节 Log4j教程 - Log4j日志格式、Log4j日志到文件
  • Android开发教程viewpager2点击指示标也能切换
  • (C#面向初学者的 .NET 的生成 AI) 第 2 部分-什么是 AI 和 ML?
  • 解读!中国人工智能大模型技术白皮书!
  • 基于SSM医药进出口交易系统的设计
  • 大语言模型(LLMs)在安全芯片设计中应用
  • Ubuntu 系统、Docker配置、Docker的常用软件配置(下)
  • Vite构建生产配置“build:prod“: “cross-env NODE_ENV=production vite build“含义
  • 「C/C++」C/C++标准库 之 <cstring> 字符串操作库
  • 【css】CSS 文本溢出显示省略号
  • Ubuntu最简单安装OpenCV
  • OpenCV基础01
  • 树莓派基本设置--4.网络设置
  • 9.排队模型-M/M/1
  • LabVIEW在Windows和Linux开发的差异
  • 学习记录:js算法(八十一):子集
  • C++算法第五天
  • 安捷伦E4991A E4990A阻抗分析仪LCR电桥3Ghz高频
  • js选项卡