Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdio>
- using namespace std;
- bool f(bool mat[50][50], bool v[50], int k, int n){
- if (v[k])
- return true;
- v[k] = true;
- bool c[50];
- for (int i = 0; i < n; i++){
- if (mat[k][i]){
- for (int j = 0; j < n; j++)
- c[j] = v[j];
- if (f(mat, c, i, n))
- return true;
- }
- }
- return false;
- }
- int main(){
- int n;
- cin >> n;
- bool mat[50][50], v[50] = {};
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- cin >> mat[i][j];
- for (int i = 0; i < n; i++){
- if (f(mat, v, i, n)){
- cout << 1 << endl;
- goto END;
- }
- }
- cout << 0 << endl;
- END:
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement