Advertisement
IlidanBabyRage

cycle.cpp

Jul 14th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. bool f(bool mat[50][50], bool v[50], int k, int n){
  8.     if (v[k])
  9.         return true;
  10.     v[k] = true;
  11.     bool c[50];
  12.     for (int i = 0; i < n; i++){
  13.         if (mat[k][i]){
  14.             for (int j = 0; j < n; j++)
  15.                 c[j] = v[j];
  16.             if (f(mat, c, i, n))
  17.                 return true;
  18.         }
  19.     }
  20.     return false;
  21. }
  22.  
  23. int main(){
  24.    
  25.     int n;
  26.     cin >> n;
  27.     bool mat[50][50], v[50] = {};
  28.     for (int i = 0; i < n; i++)
  29.         for (int j = 0; j < n; j++)
  30.             cin >> mat[i][j];
  31.  
  32.     for (int i = 0; i < n; i++){
  33.         if (f(mat, v, i, n)){
  34.             cout << 1 << endl;
  35.             goto END;
  36.         }
  37.     }
  38.     cout << 0 << endl;
  39.  
  40.     END:
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement