Language: C++

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
#include <queue>
#include <vector>
#define INF 1e9
typedef long long ll;
using namespace std;

map<ll,int> index;
typedef pair<int,int> P;
int dp[500000];
int fie[500000][9];
int wx[500000];
int next[4]={-3,-1,3,1};
int perm[10];
int ch,cv;
ll s,g;

int func(){
	for(int i=0;i<500000;i++){
		dp[i]=INF;
	}
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,s));
	dp[s]=0;
	while(1){
		P q=que.top();
		que.pop();
		int x=q.second,c=q.first;
		if(c>dp[x])continue;
		if(x==g)return c;
		for(int i=0;i<4;i++){
			swap(fie[x][wx[x]],fie[x][(wx[x]+next[i]+9)%9]);
			ll sum=0,pp=1;
			for(int j=0;j<9;j++){
				sum+=(ll)pp*fie[x][j];
				pp*=10;
			}
			sum=index[sum];
			int nc=c+ch;
			if(i%2==0)nc=c+cv;
			if(dp[sum]>nc){
				dp[sum]=nc;
				que.push(P(nc,sum));
			}
			swap(fie[x][wx[x]],fie[x][(wx[x]+next[i]+9)%9]);
		}
	}
	return -1;
}

int main(void){
	for(int i=0;i<9;i++){
		perm[i]=i;
	}
	int cnt=0;
	do{
		ll pp=1,sum=0;
		for(int i=0;i<9;i++){
			sum+=(ll)pp*perm[i];
			fie[cnt][i]=perm[i];
			if(perm[i]==0){
				wx[cnt]=i;
			}
			pp*=10LL;
		}
		index[sum]=cnt;
		cnt++;
	}while(next_permutation(perm,perm+9));
	while(1){
		scanf("%d %d",&ch,&cv);
		if(ch==0 && cv==0)break;
		s=0,g=0;
		ll pp=1;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				ll a;
				scanf("%lld",&a);
				s+=pp*a;
				pp*=10LL;
			}
		}
		pp=1;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				ll a;
				scanf("%lld",&a);
				g+=pp*a;
				pp*=10LL;
			}
		}
		s=index[s];
		g=index[g];
		printf("%d\n",func());
	}
	return 0;
}

Compiler output:
a.cc:13:13: error: 'std::map<long long int, int> index' redeclared as different kind of entity
   13 | map<ll,int> index;
      |             ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from a.cc:2:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'int func()':
a.cc:37:58: error: reference to 'next' is ambiguous
   37 |                         swap(fie[x][wx[x]],fie[x][(wx[x]+next[i]+9)%9]);
      |                                                          ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/vector:62,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:18:5: note:                 'int next [4]'
   18 | int next[4]={-3,-1,3,1};
      |     ^~~~
a.cc:43:34: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   43 |                         sum=index[sum];
      |                                  ^
a.cc:50:58: error: reference to 'next' is ambiguous
   50 |                         swap(fie[x][wx[x]],fie[x][(wx[x]+next[i]+9)%9]);
      |                                                          ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:18:5: note:                 'int next [4]'
   18 | int next[4]={-3,-1,3,1};
      |     ^~~~
a.cc: In function 'int main()':
a.cc:71:22: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   71 |                 index[sum]=cnt;
      |                      ^
a.cc:96:24: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   96 |                 s=index[s];
      |                        ^
a.cc:97:24: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript
   97 |                 g=index[g];
      |                        ^