fork(2) download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <string>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.  
  8. int mat[100][100];
  9. int mark[100];
  10. int pos[4][2] = {{-1, 0}, {0, 1}, {0, -1}, {1, 0}};
  11. int part, n, x, y;
  12. bool b;
  13. string str;
  14.  
  15. void dfs (int a, int b)
  16. {
  17. mat[a][b] = -1;
  18. for (int i = 0; i < 4; i++)
  19. {
  20. int t1 = a + pos[i][0];
  21. int t2 = b + pos[i][1];
  22. if (t1 >= 0 && t1 < n && t2 >= 0 && t2 < n && mat[t1][t2] == part)
  23. dfs (t1, t2);
  24. }
  25. }
  26.  
  27. int main ()
  28. {
  29. while (cin >> n && n != 0)
  30. {
  31. for (int i = 0; i < n; i++)
  32. memset (mat[i], 0, sizeof mat[i]);
  33. memset (mark, 0, sizeof mark);
  34. getline (cin, str);
  35. for (int i = 1; i < n; i++)
  36. {
  37. getline (cin, str);
  38. stringstream ss (str);
  39. while (ss >> x >> y)
  40. mat[x-1][y-1] = i;
  41. }
  42. bool b = true;
  43. for (int i = 0; b && i < n; i++)
  44. for (int j = 0; j < n; j++)
  45. if (mat[i][j] >= 0)
  46. {
  47. part = mat[i][j];
  48. if (mark[part])
  49. {
  50. b = false;
  51. break;
  52. }
  53. else
  54. {
  55. mark[part]= 1;
  56. dfs (i, j);
  57. }
  58. }
  59. if (b)
  60. cout << "good" << endl;
  61. else
  62. cout << "wrong" << endl;
  63. }
  64. return 0;
  65. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty