#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using ull = unsigned long long; using Graph = vector>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define NP next_permutation const int INF32 = 2e9; const ll INF64 = 2e18; const ll mod = 998244353; // const ll mod = 1e9 + 7; template bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;} template bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;} void cincout() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } ll Pow(ll a, int b) { ll ret = 1; for (int i = 0; i < b; i++) ret *= a; return ret; } int main() { cincout(); int N, M, K; cin >> N >> M >> K; vector A(K); vector> T(N, vector(N)); for (int i = 0; i < K; i++) cin >> A[i], A[i]--; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> T[i][j]; int ans = INF32; vector P(N); for (int i = 0; i < M; i++) P[i] = 1; sort(all(P)); do { vector place; for (int k = 0; k < N; k++) if (P[k]) place.push_back(k); vector B(M); iota(all(B), 0); do { int time = 0; for (int i = 1; i < M; i++) time += T[place[B[i - 1]]][place[B[i]]]; int minimum = INF32; for (int i = 0; i < K; i++) chmin(minimum, T[place[B.back()]][A[i]]); chmin(ans, time + minimum); } while (NP(all(B))); } while (NP(all(P))); cout << ans << endl; }