#include #include #include #include using namespace std; const int maxs=20; const int maxn=150; const int dx[]={1,-1,0,0,0}; const int dy[]={0,0,1,-1,0}; inline int ID(int a,int b,int c) { return (a<<16)|(b<<8)|c; } int s[3],t[3]; int deg[maxn],G[maxn][5]; inline bool error(int a, int b, int a2, int b2) { return a2==b2||(a2==b&&b2==a); } int d[maxn][maxn][maxn]; int bfs() { queue q; memset(d,-1,sizeof(d)); q.push(ID(s[0],s[1],s[2])); d[s[0]][s[1]][s[2]]=0; while(!q.empty()) { int u=q.front(); q.pop(); int a=(u>>16)&0xff,b=(u>>8)&0xff,c=u&0xff; if(a==t[0]&&b==t[1]&&c==t[2]) return d[a][b][c]; for(int i=0;i