Language: C++

#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); if (n == 0) cout << endl; REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

template<typename T> void warshall_floyd(vector<vector<T>>& g) {
    int n = sz(g);
    REP(k, n) REP(i, n) REP(j, n) chmin(g[i][j] ,g[i][k] + g[k][j]);
}

void solve() {
    int h, w;
    cin >> h >> w;
    vvl c(10, vl(10));
    REP(i, 10) REP(j, 10) cin >> c[i][j];
    vl a(10);
    int x;
    REP(i, h * w) {
        cin >> x;
        if (x > 0) a[x]++;
    }
    warshall_floyd(c);

    ll ans = 0;
    FOR(i, 2, 10) ans += c[i][1] * a[i];
    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); if (n == 0) cout << endl; REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

template<typename T> void warshall_floyd(vector<vector<T>>& g) {
    int n = sz(g);
    REP(k, n) REP(i, n) REP(j, n) chmin(g[i][j] ,g[i][k] + g[k][j]);
}

void solve() {
    int h, w;
    cin >> h >> w;
    vvl c(10, vl(10));
    REP(i, 10) REP(j, 10) cin >> c[i][j];
    vl a(10);
    int x;
    REP(i, h * w) {
        cin >> x;
        if (x > 0) a[x]++;
    }
    warshall_floyd(c);

    ll ans = 0;
    FOR(i, 2, 10) ans += c[i][1] * a[i];
    cout << ans << endl;
}


Compiler output:
a.cc:91:31: error: redefinition of 'template<class T> bool chmin(T&, T)'
   91 | template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
      |                               ^~~~~
a.cc:25:31: note: 'template<class T> bool chmin(T&, T)' previously declared here
   25 | template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
      |                               ^~~~~
a.cc:92:31: error: redefinition of 'template<class T> bool chmax(T&, T)'
   92 | template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
      |                               ^~~~~
a.cc:26:31: note: 'template<class T> bool chmax(T&, T)' previously declared here
   26 | template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
      |                               ^~~~~
a.cc:93:31: error: redefinition of 'template<class T> void prn(std::vector<_Tp>&)'
   93 | template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
      |                               ^~~
a.cc:27:31: note: 'template<class T> void prn(std::vector<_Tp>&)' previously declared here
   27 | template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
      |                               ^~~
a.cc:94:31: error: redefinition of 'template<class T> void printv(std::vector<_Tp>&)'
   94 | template<class T> inline void printv(vector<T>& v) {int n = sz(v); if (n == 0) cout << endl; REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
      |                               ^~~~~~
a.cc:28:31: note: 'template<class T> void printv(std::vector<_Tp>&)' previously declared here
   28 | template<class T> inline void printv(vector<T>& v) {int n = sz(v); if (n == 0) cout << endl; REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
      |                               ^~~~~~
a.cc:95:31: error: redefinition of 'template<class T> void printvv(std::vector<std::vector<_Tp> >&)'
   95 | template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
      |                               ^~~~~~~
a.cc:29:31: note: 'template<class T> void printvv(std::vector<std::vector<_Tp> >&)' previously declared here
   29 | template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
      |                               ^~~~~~~
a.cc:96:31: error: redefinition of 'template<class T> void printlnv(std::vector<_Tp>&)'
   96 | template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
      |                               ^~~~~~~~
a.cc:30:31: note: 'template<class T> void printlnv(std::vector<_Tp>&)' previously declared here
   30 | template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
      |                               ^~~~~~~~
a.cc:97:11: error: redefinition of 'const int MOD'
   97 | const int MOD = 1000000007;
      |           ^~~
a.cc:31:11: note: 'const int MOD' previously defined here
   31 | const int MOD = 1000000007;
      |           ^~~
a.cc:98:11: error: redefinition of 'const int INF'
   98 | const int INF = 1000000001;
      |           ^~~
a.cc:32:11: note: 'const int INF' previously defined here
   32 | const int INF = 1000000001;
      |           ^~~
a.cc:99:10: error: redefinition of 'const ll LINF'
   99 | const ll LINF = 1000000001000000001LL;
      |          ^~~~
a.cc:33:10: note: 'const ll LINF' previously defined here
   33 | const ll LINF = 1000000001000000001LL;
      |          ^~~~
a.cc:103:5: error: redefinition of 'int main()'
  103 | int main() {
      |     ^~~~
a.cc:37:5: note: 'int main()' previously defined here
   37 | int main() {
      |     ^~~~
a.cc:111:27: error: redefinition of 'template<class T> void warshall_floyd(std::vector<std::vector<_Tp> >&)'
  111 | template<typename T> void warshall_floyd(vector<vector<T>>& g) {
      |                           ^~~~~~~~~~~~~~
a.cc:45:27: note: 'template<class T> void warshall_floyd(std::vector<std::vector<_Tp> >&)' previously declared here
   45 | template<typename T> void warshall_floyd(vector<vector<T>>& g) {
      |                           ^~~~~~~~~~~~~~
a.cc:116:6: error: redefinition of 'void solve()'
  116 | void solve() {
      |      ^~~~~
a.cc:50:6: note: 'void solve()' previously defined here
   50 | void solve() {
      |      ^~~~~