fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int N;
  6. int A[102][102];
  7. int read ()
  8. {
  9. cin>>N;
  10. if (N==0) return 0;
  11. for (int i=1; i<=N; i++)
  12. {
  13. for (int j=1; j<=N; j++)
  14. {
  15. cin>>A[i][j];
  16. }
  17. }
  18. return 1;
  19. }
  20.  
  21. int phanNhom()
  22. {
  23. vector <int> N1;
  24. vector <int> N2;
  25. for (int i=1; i<=N; i++)
  26. {
  27. int kt1=0;
  28. for (int j=0; j<N1.size(); j++)
  29. {
  30. if (A[i][N1[j]]==1)
  31. {
  32. kt1 = 1;
  33. break;
  34. }
  35. }
  36. int kt2=0;
  37. for (int j=0; j<N2.size(); j++)
  38. {
  39. if (A[i][N2[j]]==1)
  40. {
  41. kt2 = 1;
  42. break;
  43. }
  44. }
  45. if (kt1==1 && kt2==0)
  46. N2.push_back(i);
  47. else if (kt1==0 && kt2==1)
  48. N1.push_back(i);
  49. else if (kt1==1 && kt2==1)
  50. return 0;
  51. else
  52. N1.push_back(i);
  53. }
  54. return 1;
  55. }
  56.  
  57. int main ()
  58. {
  59. while (read())
  60. {
  61. if (phanNhom()==1)
  62. cout<<"YES"<<endl;
  63. else
  64. cout<<"NO"<<endl;
  65. }
  66. return 0;
  67. }
Success #stdin #stdout 0s 4500KB
stdin
11
0 1 0 0 1 1 0 0 0 0 0
1 0 1 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 0 0 1 0 0
1 0 0 1 0 0 0 0 0 0 0
1 0 0 1 0 0 1 0 0 0 0
0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 0 0 0 0 1 1 0
0 0 0 1 0 0 0 1 0 0 0
0 0 0 0 0 0 1 1 0 0 1
0 0 0 0 0 0 0 0 0 1 0
0
stdout
YES