這題根本就是在考空間概念跟怎麼耐心的觀察邊常輸入
然後就是無腦Dijkstra :)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int main(void){
ios::sync_with_stdio(0),cin.tie(0);
int S,T,w;
while (cin>>S>>T){
vector<pii> g[13];
//input~~
for (int i=2 ; i<=6 ; i++){//1~5
cin>>w;
g[1].push_back({i,w});
g[i].push_back({1,w});
}
for (int i=2 ; i<=5 ; i++){//6~9
cin>>w;
g[i].push_back({i+1,w});
g[i+1].push_back({i,w});
}
cin>>w;//10
g[2].push_back({6,w});
g[6].push_back({2,w});
for (int i=2 ; i<=3 ; i++){//11~14
cin>>w;
g[i].push_back({11-i,w});
g[11-i].push_back({i,w});
cin>>w;
g[i].push_back({10-i,w});
g[10-i].push_back({i,w});
}
cin>>w;//15,16
g[4].push_back({7,w});
g[7].push_back({4,w});
cin>>w;
g[4].push_back({11,w});
g[11].push_back({4,w});
for (int i=5 ; i<=6 ; i++){//17~20
cin>>w;
g[i].push_back({16-i,w});
g[16-i].push_back({i,w});
cin>>w;
g[i].push_back({15-i,w});
g[15-i].push_back({i,w});
}
for (int i=7 ; i<=10 ; i++){//21~24
cin>>w;
g[i].push_back({i+1,w});
g[i+1].push_back({i,w});
}
cin>>w;//25
g[7].push_back({11,w});
g[11].push_back({7,w});
for (int i=7 ; i<=11 ; i++){//26~30
cin>>w;
g[12].push_back({i,w});
g[i].push_back({12,w});
}
priority_queue<pii,vector<pii>,greater<pii>> pq;
vector<int> dis(13,1e6+5);
bool ok = false;
dis[S] = 0;
pq.push({0,S});
while (!pq.empty()){
auto [d,u] = pq.top();pq.pop();
if (d>dis[u]) continue;
if (u == T){
cout<<dis[T]<<"\n";
break;
}
for (auto [v,w]:g[u]){
if (dis[v] > dis[u]+w){
dis[v] = dis[u]+w;
pq.push({dis[v],v});
}
}
}
}
}