#include #include #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; int inf = 1e9; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; int dp[1 << n][n]; rep(i, 0, 1 << n) rep(j, 0, n) dp[i][j] = inf; rep(i, 0, k) { int x; cin >> x, x--; dp[1 << x][x] = 0; } vector> a(n, vector(n)); rep(i, 0, n) rep(j, 0, n) cin >> a[i][j]; int ans = inf; vector> order; rep(i, 1, 1 << n) order.emplace_back(__builtin_popcount(i), i); sort(order.begin(), order.end()); for (auto [_, mask] : order) { rep(i, 0, n) { if (dp[mask][i] == inf) continue; rep(j, 0, n) { if (mask & (1 << j)) continue; dp[mask | (1 << j)][j] = min(dp[mask][i] + a[i][j], dp[mask | (1 << j)][j]); } } } rep(i, 0, 1 << n) { if (__builtin_popcount(i) == m) { rep(j, 0, n) { ans = min(ans, dp[i][j]); } } } cout << ans << endl; }