HDU 2181 world of Hamilton Bypass
World Problems of the Hamilton BypassTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1510 Accepted Submission (s): 960
Problem Description is a regular solid 12-axis. Its 20 vertices mark the world's 20 famous cities. You set off from a city and go back to the city just once.
The first 20 rows of Input have three numbers in row I, indicating the three cities adjacent to the city I. after 20th rows, each row has 1 MB, m <= 20, m> = 1.m= 0 and exits.
Output outputs all the routes that are returned to m once every city starting from the m city. If there are multiple routes, Output them in lexicographically. Each line has one route. the first route of each line. next, list the cities that pass. see Sample output
Sample Input
2 5 201 3 122 4 103 5 81 4 65 7 196 8 174 7 98 10 163 9 1110 12 152 11 1312 14 2013 15 1811 14 169 15 177 16 1814 17 196 18 201 13 1950
Sample Output
1: 5 1 2 3 4 8 7 17 18 14 15 16 9 10 11 12 13 20 19 6 52: 5 1 2 3 4 8 9 10 11 12 13 20 19 18 14 15 16 17 7 6 53: 5 1 2 3 10 9 16 17 18 14 15 11 12 13 20 19 6 7 8 4 54: 5 1 2 3 10 11 12 13 20 19 6 7 17 18 14 15 16 9 8 4 55: 5 1 2 12 11 10 3 4 8 9 16 15 14 13 20 19 18 17 7 6 56: 5 1 2 12 11 15 14 13 20 19 18 17 16 9 10 3 4 8 7 6 57: 5 1 2 12 11 15 16 9 10 3 4 8 7 17 18 14 13 20 19 6 58: 5 1 2 12 11 15 16 17 18 14 13 20 19 6 7 8 9 10 3 4 59: 5 1 2 12 13 20 19 6 7 8 9 16 17 18 14 15 11 10 3 4 510: 5 1 2 12 13 20 19 18 14 15 11 10 3 4 8 9 16 17 7 6 511: 5 1 20 13 12 2 3 4 8 7 17 16 9 10 11 15 14 18 19 6 512: 5 1 20 13 12 2 3 10 11 15 14 18 19 6 7 17 16 9 8 4 513: 5 1 20 13 14 15 11 12 2 3 10 9 16 17 18 19 6 7 8 4 514: 5 1 20 13 14 15 16 9 10 11 12 2 3 4 8 7 17 18 19 6 515: 5 1 20 13 14 15 16 17 18 19 6 7 8 9 10 11 12 2 3 4 516: 5 1 20 13 14 18 19 6 7 17 16 15 11 12 2 3 10 9 8 4 517: 5 1 20 19 6 7 8 9 10 11 15 16 17 18 14 13 12 2 3 4 518: 5 1 20 19 6 7 17 18 14 13 12 2 3 10 11 15 16 9 8 4 519: 5 1 20 19 18 14 13 12 2 3 4 8 9 10 11 15 16 17 7 6 520: 5 1 20 19 18 17 16 9 10 11 15 14 13 12 2 3 4 8 7 6 521: 5 4 3 2 1 20 13 12 11 10 9 8 7 17 16 15 14 18 19 6 522: 5 4 3 2 1 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 523: 5 4 3 2 12 11 10 9 8 7 6 19 18 17 16 15 14 13 20 1 524: 5 4 3 2 12 13 14 18 17 16 15 11 10 9 8 7 6 19 20 1 525: 5 4 3 10 9 8 7 6 19 20 13 14 18 17 16 15 11 12 2 1 526: 5 4 3 10 9 8 7 17 16 15 11 12 2 1 20 13 14 18 19 6 527: 5 4 3 10 11 12 2 1 20 13 14 15 16 9 8 7 17 18 19 6 528: 5 4 3 10 11 15 14 13 12 2 1 20 19 18 17 16 9 8 7 6 529: 5 4 3 10 11 15 14 18 17 16 9 8 7 6 19 20 13 12 2 1 530: 5 4 3 10 11 15 16 9 8 7 17 18 14 13 12 2 1 20 19 6 531: 5 4 8 7 6 19 18 17 16 9 10 3 2 12 11 15 14 13 20 1 532: 5 4 8 7 6 19 20 13 12 11 15 14 18 17 16 9 10 3 2 1 533: 5 4 8 7 17 16 9 10 3 2 1 20 13 12 11 15 14 18 19 6 534: 5 4 8 7 17 18 14 13 12 11 15 16 9 10 3 2 1 20 19 6 535: 5 4 8 9 10 3 2 1 20 19 18 14 13 12 11 15 16 17 7 6 536: 5 4 8 9 10 3 2 12 11 15 16 17 7 6 19 18 14 13 20 1 537: 5 4 8 9 16 15 11 10 3 2 12 13 14 18 17 7 6 19 20 1 538: 5 4 8 9 16 15 14 13 12 11 10 3 2 1 20 19 18 17 7 6 539: 5 4 8 9 16 15 14 18 17 7 6 19 20 13 12 11 10 3 2 1 540: 5 4 8 9 16 17 7 6 19 18 14 15 11 10 3 2 12 13 20 1 541: 5 6 7 8 4 3 2 12 13 14 15 11 10 9 16 17 18 19 20 1 542: 5 6 7 8 4 3 10 9 16 17 18 19 20 13 14 15 11 12 2 1 543: 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 544: 5 6 7 8 9 16 17 18 19 20 1 2 12 13 14 15 11 10 3 4 545: 5 6 7 17 16 9 8 4 3 10 11 15 14 18 19 20 13 12 2 1 546: 5 6 7 17 16 15 11 10 9 8 4 3 2 12 13 14 18 19 20 1 547: 5 6 7 17 16 15 11 12 13 14 18 19 20 1 2 3 10 9 8 4 548: 5 6 7 17 16 15 14 18 19 20 13 12 11 10 9 8 4 3 2 1 549: 5 6 7 17 18 19 20 1 2 3 10 11 12 13 14 15 16 9 8 4 550: 5 6 7 17 18 19 20 13 14 15 16 9 8 4 3 10 11 12 2 1 551: 5 6 19 18 14 13 20 1 2 12 11 15 16 17 7 8 9 10 3 4 552: 5 6 19 18 14 15 11 10 9 16 17 7 8 4 3 2 12 13 20 1 553: 5 6 19 18 14 15 11 12 13 20 1 2 3 10 9 16 17 7 8 4 554: 5 6 19 18 14 15 16 17 7 8 9 10 11 12 13 20 1 2 3 4 555: 5 6 19 18 17 7 8 4 3 2 12 11 10 9 16 15 14 13 20 1 556: 5 6 19 18 17 7 8 9 16 15 14 13 20 1 2 12 11 10 3 4 557: 5 6 19 20 1 2 3 10 9 16 15 11 12 13 14 18 17 7 8 4 558: 5 6 19 20 1 2 12 13 14 18 17 7 8 9 16 15 11 10 3 4 559: 5 6 19 20 13 12 11 10 9 16 15 14 18 17 7 8 4 3 2 1 560: 5 6 19 20 13 14 18 17 7 8 4 3 10 9 16 15 11 12 2 1 5
Author Zhousc
Source ecjtu2008 Summer Contest
A deep search .. Never be scared by the output ..
#include
#include
#include using namespace std;#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;#define mod 1e9+9#define inf 0x7f7f7f7f#define N 1005#define MAXN 15#define eps 1e-6int a[25];int vis[25];int mat[25][25];int m;int c;void dfs(int o,int n,int q){ a[n]=o; vis[o]=1; int i,j; for(i=0; i<3; i++) { int s=mat[o][i]; if(n==19 &&s==q) { printf("%d: ",++c); for(j=0; j<20; j++) { if(j!=20) printf("%d ",a[j]); else printf("%d",a[j]); } printf("%d\n",m); } if(!vis[s]) dfs(s,n+1,q); } vis[o]=0;}int main(){ int i; for(i=1; i<=20; i++) scanf("%d%d%d",&mat[i][0],&mat[i][1],&mat[i][2]); while(scanf("%d",&m)&&m) { c=0; memset(a,0,sizeof(a)); memset(vis,0,sizeof(vis)); dfs(m,0,m); } return 0;}