#include #include #include #include #include #include #include #include #include using ll = int; const ll maxn=5e4+5,maxk=51,inf=1e9+7; ll n,k,b[maxn]; std::vector> edg; std::vector> classp; ll vis[maxn]; struct P{ ll now,step; inline bool operator<(const P&o)const{ return step>o.step; } }; #define printf int main(){ std::iostream::sync_with_stdio(false); std::cin.tie(nullptr); std::cin>>n>>k; edg.resize(k+1); classp.resize(k+1); for(ll i=1;i<=n;i++){ std::cin>>b[i]; classp[b[i]].emplace_back(i); vis[i]=inf; } for(ll i=1;i<=k;i++){ for(ll j=1;j<=k;j++){ char tmp; std::cin>>tmp; if(tmp=='1'){ edg[i].emplace_back(j); } } } std::priority_queue

pq; pq.emplace(1,0); while(pq.size()){ auto[now,step]=pq.top(); pq.pop(); if(vis[now]!=inf)continue; vis[now]=std::min(step,vis[now]); printf("dij now=%lld, step=%lld\n",now,step); if(now==n){ std::cout<vis[p])continue; pq.emplace(p,step+std::abs(p-now)); } } } std::cout<<"-1\n"; }