Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- using namespace std;
- vector<vector<int>>B1;
- int lelus,it;
- bool kekus(int a){
- if(a == it){
- return true;
- }
- if (a == 0){
- return false;
- }
- for(int i = 0;i < lelus; ++i){
- if(B1[i][0] == a){
- return kekus(B1[i][1]);
- }
- }
- return false;
- }
- int main(){
- int a,b,d = 0;
- cin>>a;
- vector<vector<int>>A(a,vector<int>(a,0));
- for(int i = 0;i < a; ++i){
- for(int h = 0; h < a; ++h){
- cin>>b;
- A[i][h] = b;
- }
- }
- for(int i = 0;i < a; ++i){
- for(int h = 0; h < a; ++h){
- if(A[i][h] == 1){
- d+=1;
- if(A[h][i] == 1){
- cout<<"1"<<endl;
- return 0;
- }
- }
- }
- }
- vector<vector<int>>B(d);
- int c = 0;
- for(int i = 0;i < a; ++i){
- for(int y = 0; y < a ; ++y){
- if(A[i][y]==1){
- B[c].push_back(i);
- B[c].push_back(y);
- c+=1;
- }
- }
- }
- B1 = B;
- lelus = d;
- for(int i = 0;i < d; ++i){
- it = B[i][0];
- if (kekus(B[i][1])){
- cout<<"1"<<endl;
- return 0;
- }
- }
- cout<<"0";
- cout<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement