Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <vector>
  3. #include <iostream>
  4. #include <functional>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int SIMB (char k)
  10. {
  11. if(k=='>') return 1;
  12. if(k=='<') return -1;
  13. if(k=='^') return -1;
  14. return 1;
  15. }
  16. vector<bool> used;
  17. vector<vector<int>> g;
  18. int k;
  19. void DFS(int st)
  20. {
  21. used[st]=true;
  22. for (int r=0; r<k; r++)
  23. if ((g[st][r]!=0) && (!used[r]))
  24. DFS(r);
  25. }
  26.  
  27.  
  28. int main()
  29. {
  30. int n,m;
  31. cin>>n;
  32. cin>>m;
  33. used=vector<bool> (n*m);
  34. vector<vector<int>> mas;
  35. for(int i=0;i<n*m;i++)
  36. {
  37. mas.push_back(vector<int> (n*m));
  38. }
  39. char*str=new char[n+m];
  40. for(int i=0;i<n+m;i++)
  41. {
  42. cin>>str[i];
  43. }
  44. int j=n;
  45. for(int i=0;i<n*m;i++)
  46. {
  47. if((i+SIMB(str[i/m])>=m*(i/m) && i+SIMB(str[i/m])<(m*(i/m))+m))
  48. {
  49. mas[i][i+SIMB(str[i/m])]=1;
  50. }
  51. if((i+m*SIMB(str[n+i%n])>=0 && i+m*SIMB(str[n+i%n])<n*m))
  52. {
  53. mas[i][i+m*SIMB(str[n+i%n])]=1;
  54. }
  55. }
  56. g=mas;
  57. k=n*m;
  58. for(int i=0;i<n*m;i++)
  59. {
  60. DFS(i);
  61. for (int k = 0; k < n*m; k++)
  62. {
  63. if(used[k])
  64. {
  65. used[k]=false;
  66. }
  67. else
  68. {
  69. cout<<"NO";
  70. return 0;
  71. }
  72. }
  73. }
  74. cout<<"YES";
  75. delete [] str;
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement