Language: C++

#include <bits/stdc++.h>
using namespace std;
int x,y;
int graph[51][51];
vector<int>colors[3];
int visit[51];
int dp[3][51];
int busquedad(int h){
    if(h==3){
        return 0;
    }
    int resp=INT_MAX;
    for(int i=0;i<y;i++){
        if(visit[i]==true) continue;
        int cont=0;
        if(dp[h][i]!=-1){
            visit[i]=true;
            resp=min(resp,dp[h][i]+busquedad(h+1));
            visit[i]=false;
            continue;
        }
        for(int d=0;d<colors[h].size();d++){
            cont+=graph[colors[h][d]][i];
        }
        visit[i]=true;
        dp[h][i]=cont;
        resp=min(resp,cont+busquedad(h+1));
        visit[i]=false;
    }
    return resp;

}
int main(){
    memset(dp,-1,sizeof(dp));
    cin>>x>>y;
    for(int i=0;i<y;i++){
        for(int d=0;d<y;d++){
            cin>>graph[i][d];
        }
    }
    for(int i=1;i<=x;i++){
        for(int d=1;d<=x;d++){
            int t;
            cin>>t;
            colors[(i+d)%3].push_back(t-1);
        }
    }


    cout<<busquedad(0)<<endl;

    return 0;
}
#include <bits/stdc++.h>
using namespace std;
int x,y;
int graph[51][51];
vector<int>colors[3];
int visit[51];
int dp[3][51];
int busquedad(int h){
    if(h==3){
        return 0;
    }
    int resp=INT_MAX;
    for(int i=0;i<y;i++){
        if(visit[i]==true) continue;
        int cont=0;
        if(dp[h][i]!=-1){
            visit[i]=true;
            resp=min(resp,dp[h][i]+busquedad(h+1));
            visit[i]=false;
            continue;
        }
        for(int d=0;d<colors[h].size();d++){
            cont+=graph[colors[h][d]][i];
        }
        visit[i]=true;
        dp[h][i]=cont;
        resp=min(resp,cont+busquedad(h+1));
        visit[i]=false;
    }
    return resp;

}
int main(){
    memset(dp,-1,sizeof(dp));
    cin>>x>>y;
    for(int i=0;i<y;i++){
        for(int d=0;d<y;d++){
            cin>>graph[i][d];
        }
    }
    for(int i=1;i<=x;i++){
        for(int d=1;d<=x;d++){
            int t;
            cin>>t;
            colors[(i+d)%3].push_back(t-1);
        }
    }


    cout<<busquedad(0)<<endl;

    return 0;
}


Compiler output:
a.cc: In function 'int busquedad(int)':
a.cc:14:12: error: reference to 'visit' is ambiguous
   14 |         if(visit[i]==true) continue;
      |            ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:5: note:                 'int visit [51]'
    6 | int visit[51];
      |     ^~~~~
a.cc:17:13: error: reference to 'visit' is ambiguous
   17 |             visit[i]=true;
      |             ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:5: note:                 'int visit [51]'
    6 | int visit[51];
      |     ^~~~~
a.cc:19:13: error: reference to 'visit' is ambiguous
   19 |             visit[i]=false;
      |             ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:5: note:                 'int visit [51]'
    6 | int visit[51];
      |     ^~~~~
a.cc:25:9: error: reference to 'visit' is ambiguous
   25 |         visit[i]=true;
      |         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:5: note:                 'int visit [51]'
    6 | int visit[51];
      |     ^~~~~
a.cc:28:9: error: reference to 'visit' is ambiguous
   28 |         visit[i]=false;
      |         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:5: note:                 'int visit [51]'
    6 | int visit[51];
      |     ^~~~~
a.cc: At global scope:
a.cc:56:5: error: redefinition of 'int x'
   56 | int x,y;
      |     ^
a.cc:3:5: note: 'int x' previously declared here
    3 | int x,y;
      |     ^
a.cc:56:7: error: redefinition of 'int y'
   56 | int x,y;
      |       ^
a.cc:3:7: note: 'int y' previously declared here
    3 | int x,y;
      |       ^
a.cc:57:5: error: redefinition of 'int graph [51][51]'
   57 | int graph[51][51];
      |     ^~~~~
a.cc:4:5: note: 'int graph [51][51]' previously declared here
    4 | int graph[51][51];
      |     ^~~~~
a.cc:58:12: error: redefinition of 'std::vector<int> colors [3]'
   58 | vector<int>colors[3];
      |            ^~~~~~
a.cc:5:12: note: 'std::vector<int> colors [3]' previously declared here
    5 | vector<int>colors[3];
      |            ^~~~~~
a.cc:59:5: error: redefinition of 'int visit [51]'
   59 | int visit[51];
      |     ^~~~~
a.cc:6:5: note: 'int visit [51]' previously declared here
    6 | int visit[51];
      |     ^~~~~
a.cc:60:5: error: redefinition of 'int dp [3][51]'
   60 | int dp[3][51];
      |     ^~
a.cc:7:5: note: 'int dp [3][51]' previously declared here
    7 | int dp[3][51];
      |     ^~
a.cc:61:5: error: redefinition of 'int busquedad(int)'
   61 | int busquedad(int h){
      |     ^~~~~~~~~
a.cc:8:5: note: 'int busquedad(int)' previously defined here
    8 | int busquedad(int h){
      |     ^~~~~~~~~
a.cc: In function 'int busquedad(int)':
a.cc:67:12: error: reference to 'visit' is ambiguous
   67 |         if(visit[i]==true) continue;
      |            ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:5: note:                 'int visit [51]'
    6 | int visit[51];
      |     ^~~~~
a.cc:70:13: error: reference to 'visit' is ambiguous
   70 |             visit[i]=true;
      |             ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:5: note:                 'int visit [51]'
    6 | int visit[51];
      |     ^~~~~
a.cc:72:13: error: reference to 'visit' is ambiguous
   72 |             visit[i]=false;
      |             ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:5: note:                 'int visit [51]'
    6 | int visit[51];
      |     ^~~~~
a.cc:78:9: error: reference to 'visit' is ambiguous
   78 |         visit[i]=true;
      |         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:5: note:                 'int visit [51]'
    6 | int visit[51];
      |     ^~~~~
a.cc:81:9: error: reference to 'visit' is ambiguous
   81 |         visit[i]=false;
      |         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:5: note:                 'int visit [51]'
    6 | int visit[51];
      |     ^~~~~
a.cc: At global scope:
a.cc:86:5: error: redefinition of 'int main()'
   86 | int main(){
      |     ^~~~
a.cc:33:5: note: 'int main()' previously defined here
   33 | int main(){
      |     ^~~~