Untitled
unknown
plain_text
2 years ago
875 B
7
Indexable
#include<iostream>
using namespace std;
int a[10][10];
int dinhcon=0;
int visit[10];
int m,n;
bool check;
bool Try(int x){
if(check == true){
return check;
}
visit[x]=0;
for(int i=x+1; i< n; i++){
if(a[i][0] == a[x][1]){
for(int k=0; k<i;k++){
if(a[i][1] == a[k][0]){
check =true;
return check;
break;
}
Try(i);
visit[x]=1;
}
}
}
}
int main(){
//freopen("input.txt", "r", stdin);
int T;
cin >> T;
for(int tc = 1; tc <= T; tc++){
for(int i=0; i<10; i++){
visit[i]=1;
}
cin >> m >> n; // m dinh va n canh
for( int i = 0; i < n; i++){
for( int j = 0; j < 2; j++){
cin >> a[i][j];
}
}
check =false;
Try(0);
cout << "Case" << " " <<"#" << tc << endl;
if(check) cout << 1 <<endl;
else cout << 0 << endl;
}
return 0;
}Editor is loading...