forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1798 - Granny's Bike.cpp
executable file
·46 lines (34 loc) · 1.04 KB
/
1798 - Granny's Bike.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
int main(){
int p[10];
for(int i=0;i<10;i++) p[i]=i+1;
bool M[11][11];
int tc=1,n,v;
string s;
bool found;
while(1){
scanf("%d\n",&n);
if(n==0) break;
memset(M,false,sizeof(M));
for(int i=1;i<=n;i++){
getline(cin,s);
istringstream is(s);
while(is>>v) M[i][v]=M[v][i]=true;
}
do{
found=true;
if(!M[0][p[0]]) found=false;
for(int i=1;i<n && found;i++)
if(!M[p[i-1]][p[i]])
found=false;
if(!found || !M[p[n-1]][0]) found=false;
}while(!found && next_permutation(p,p+n));
printf("Case %d: ",tc++);
if(found) printf("Granny can make the circuit.\n");
else printf("Granny can not make the circuit.\n");
}
}