Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <vector>
- #include <iostream>
- #include <functional>
- #include <algorithm>
- using namespace std;
- int SIMB (char k)
- {
- if(k=='>') return 1;
- if(k=='<') return -1;
- if(k=='^') return -1;
- return 1;
- }
- vector<bool> used;
- vector<vector<int>> g;
- int k;
- void DFS(int st)
- {
- used[st]=true;
- for (int r=0; r<k; r++)
- if ((g[st][r]!=0) && (!used[r]))
- DFS(r);
- }
- int main()
- {
- int n,m;
- cin>>n;
- cin>>m;
- used=vector<bool> (n*m);
- vector<vector<int>> mas;
- for(int i=0;i<n*m;i++)
- {
- mas.push_back(vector<int> (n*m));
- }
- char*str=new char[n+m];
- for(int i=0;i<n+m;i++)
- {
- cin>>str[i];
- }
- int j=n;
- for(int i=0;i<n*m;i++)
- {
- if((i+SIMB(str[i/m])>=m*(i/m) && i+SIMB(str[i/m])<(m*(i/m))+m))
- {
- mas[i][i+SIMB(str[i/m])]=1;
- }
- if((i+m*SIMB(str[n+i%n])>=0 && i+m*SIMB(str[n+i%n])<n*m))
- {
- mas[i][i+m*SIMB(str[n+i%n])]=1;
- }
- }
- g=mas;
- k=n*m;
- for(int i=0;i<n*m;i++)
- {
- DFS(i);
- for (int k = 0; k < n*m; k++)
- {
- if(used[k])
- {
- used[k]=false;
- }
- else
- {
- cout<<"NO";
- return 0;
- }
- }
- }
- cout<<"YES";
- delete [] str;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement