分析
这题有几种做法。
- Tarjan
- BFS
- 只考虑外圈是否连通(我的做法)
代码
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define il inline
#define re register
#define tie0 cin.tie(0),cout.tie(0)
#define fastio ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
template<typename T>inline void read(T &x){
T f=1;x=0;char c;
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=x*10+(c^48);
x*=f;
}
int n,m;
char ns[21],we[21];
int main(){
read(n),read(m);
cin>>we>>ns;
--n,--m;
if(ns[m]=='^'&&we[0]=='>') {puts("NO");exit(0);}
if(ns[0]=='^'&&we[0]=='<') {puts("NO");exit(0);}
if(ns[0]=='v'&&we[n]=='<') {puts("NO");exit(0);}
if(ns[m]=='v'&&we[n]=='>') {puts("NO");exit(0);}
puts("YES");
return 0;
}