#ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include #include using namespace atcoder; using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < (ll)n; i++) #define all(v) v.begin(),v.end() const ll INF = (ll)2e18; void warshall_floyd(vector> &dist) { int V = dist.size(); for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N, M, K; cin >> N >> M >> K; vector A(K); set destinations; rep(i, K){ cin >> A[i]; A[i]--; destinations.insert(A[i]); } vector> T(N, vector(N)); rep(i,N){ rep(j,N){ cin >> T[i][j]; } } warshall_floyd(T); ll ans = INF; rep(i,(1LL< pos; rep(j,N){ if((i>>j)&1){ pos.push_back(j); } } vector order(M); rep(j,M){ order[j] = j; } do{ ll sum = 0; rep(j,M-1){ sum += T[pos[order[j]]][pos[order[j + 1]]]; } if(!destinations.count(pos[order.back()])){ ll MIN = INF; rep(j,K){ MIN = min(MIN, T[pos[order.back()]][A[j]]); } sum += MIN; } ans = min(ans, sum); } while (next_permutation(all(order))); } cout << ans << endl; }