Advertisement
MatveyL

цикл

Jan 17th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. vector<vector<int>>B1;
  9. int lelus,it;
  10.  
  11. bool kekus(int a){
  12. if(a == it){
  13. return true;
  14. }
  15. if (a == 0){
  16. return false;
  17. }
  18. for(int i = 0;i < lelus; ++i){
  19. if(B1[i][0] == a){
  20. return kekus(B1[i][1]);
  21. }
  22. }
  23. return false;
  24. }
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. int main(){
  34. int a,b,d = 0;
  35. cin>>a;
  36. vector<vector<int>>A(a,vector<int>(a,0));
  37.  
  38.  
  39.  
  40. for(int i = 0;i < a; ++i){
  41. for(int h = 0; h < a; ++h){
  42. cin>>b;
  43. A[i][h] = b;
  44. }
  45. }
  46.  
  47.  
  48.  
  49. for(int i = 0;i < a; ++i){
  50. for(int h = 0; h < a; ++h){
  51. if(A[i][h] == 1){
  52. d+=1;
  53. if(A[h][i] == 1){
  54. cout<<"1"<<endl;
  55. return 0;
  56. }
  57. }
  58. }
  59. }
  60.  
  61.  
  62.  
  63. vector<vector<int>>B(d);
  64. int c = 0;
  65.  
  66.  
  67. for(int i = 0;i < a; ++i){
  68. for(int y = 0; y < a ; ++y){
  69. if(A[i][y]==1){
  70. B[c].push_back(i);
  71. B[c].push_back(y);
  72. c+=1;
  73. }
  74.  
  75. }
  76. }
  77.  
  78.  
  79.  
  80. B1 = B;
  81. lelus = d;
  82.  
  83.  
  84.  
  85. for(int i = 0;i < d; ++i){
  86. it = B[i][0];
  87. if (kekus(B[i][1])){
  88. cout<<"1"<<endl;
  89. return 0;
  90. }
  91. }
  92. cout<<"0";
  93. cout<<endl;
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement