fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool t[100][100];
  5. int x, a, b, n, m;
  6.  
  7. void search(int x, int y)
  8. {
  9. t[x][y] = 1;
  10. if(x != 0)
  11. {
  12. if(!t[x-1][y]) search(x-1, y);
  13. }
  14. if(x < n)
  15. {
  16. if(!t[x+1][y]) search(x+1, y);
  17. }
  18. if(y < m)
  19. {
  20. if(!t[x][y+1]) search(x, y+1);
  21. }
  22. if(y != 0)
  23. {
  24. if(!t[x][y-1]) search(x, y-1);
  25. }
  26. }
  27.  
  28. int main()
  29. {
  30. cin>>n>>m;
  31.  
  32. for(int i = 0; i<n; i++)
  33. {
  34. for(int i = 0; i<m; i++)
  35. {
  36. cin>>x;
  37. if(x == 2)
  38. {
  39. t[n][m] = 0;
  40. a = n;
  41. b = m;
  42. }
  43. else t[n][m] = x;
  44. }
  45. }
  46. cout<<t[1][2]<<" ";
  47. search(0, 0);
  48.  
  49. if(t[a][b] == 1) cout<<1;
  50. else cout<<0;
  51.  
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5420KB
stdin
3 11
0 1 1 1 1 1 1 1 1 1 1 
1 0 0 1 0 0 0 0 0 1 1 
1 0 0 1 0 0 1 0 0 1 2 
stdout
0 1