#include #include #include #include #include #include #include #include #include #include using namespace std; using i64 = int64_t; // using u64 = uint64_t; template using VV = vector>; #define REP(i, n) for(i64 i = 0; i < i64(n); i++) #define REP1(i, n) for(i64 i = 1; i <= i64(n); i++) i64 INF = 100100100100100L; i64 direct[8][2] = { {1, 0}, {0, -1}, {-1, 0}, {0, 1}, {1, -1}, {-1, -1}, {-1, 1}, {1, 1} }; template ostream &operator<<(ostream &os, pair p); template ostream &operator<<(ostream &os, const vector &v) { for(i64 i = 0; i < i64(v.size()); i++) { if (i > 0) os << ' '; os << v[i]; } return os; } template ostream &operator<<(ostream &os, const set &st) { bool first = true; for(const T &it: st) if (first) { first = false; os << it; } else{ os << ' ' << it; } return os; } template ostream &operator<<(ostream &os, map &mp) { bool first = true; for(const auto &[f, l]: mp) if (first) { first = false; os << '{' << f << "-> " << l << '}'; } else{ os << ", {" << f << "-> " << l << '}'; } return os; } template ostream &operator<<(ostream &os, pair p) { os << '{' << p.first << ", " << p.second << '}'; return os; } int main() { i64 N, M, K; cin >> N >> M >> K; vector A(K); for(i64 &it :A) { cin >> it; it--; } VV T(N, vector(N)); for(i64 i = 0; i < N; i++) for(i64 j = 0; j < N; j++) cin >> T[i][j]; VV dp(N, vector(1 << N, INF)); deque> deq; for(i64 i = 0; i < N; i++) { dp[i][1 << i] = 0; deq.push_back({i, 1 << i}); } while (!deq.empty()) { auto [pos, bits] = deq.front(); deq.pop_front(); for(i64 i = 0; i < N; i++) { if ((bits & (1 << i)) > 0) continue; if (dp[i][(bits | (1 << i))] > dp[pos][bits] + T[pos][i]) { dp[i][(bits | (1 << i))] = dp[pos][bits] + T[pos][i]; deq.push_back({i, (bits | (1 << i))}); } } } i64 ans = INF; for(i64 a: A) { for(i64 i = 1; i < (1 << N); i++) if (__builtin_popcount(i) >= M) ans = min(ans, dp[a][i]); } /* for(auto &v: dp) { for(i64 it: v) cout << (it < INF ? it : -1) << ' '; cout << endl; } */ cout <