func_code_string: #include <bits/stdc++.h>   using namespace std;   struct arc_t {     int u, v, c;     arc_t(int _u, int _v, int _c) : u(_u), v(_v), c(_c) {}     bool operator<(const arc_t& rhs) const { return c < rhs.c; }   };   int pa[2001];   void set_init(int n) {     for (int i = 1; i <= n; i++) pa[i] = i;   }   int set_find(int x) { return pa[x] == x ? x : pa[x] = set_find(pa[x]); }   int set_union(int x, int y) {     x = set_find(x);     y = set_find(y);     if (x == y) {       return -1;     }     pa[y] = x;     return 0;   }   int f[2001][2001];   vector<pair<int, int> > G[2001];   long long d[2001][2001];   int root;   vector<bool> mark;   int dfs(int u) {     mark[u] = true;     for (vector<pair<int, int> >::iterator i = G[u].begin(); i != G[u].end();          i++) {       int v = i->first;       if (!mark[v]) {         d[root][v] = d[root][u] + i->second;         dfs(v);       }     }   }   int getd(int _r) {     root = _r;     mark.clear();     mark.resize(2001, false);     d[_r][_r] = 0;     dfs(_r);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &f[i][j]);     vector<arc_t> arc;     arc.reserve(n * n / 2 + 1);     for (int i = 1; i <= n; i++) {       if (f[i][i]) {         puts( NO );         return 0;       }       for (int j = i + 1; j <= n; j++) {         if (!f[i][j] || f[i][j] != f[j][i]) {           puts( NO );           return 0;         }         arc.push_back(arc_t(i, j, f[i][j]));       }     }     sort(arc.begin(), arc.end());     set_init(n);     for (vector<arc_t>::iterator it = arc.begin(); it != arc.end(); it++) {       if (!set_union(it->u, it->v)) {         G[it->u].push_back(make_pair(it->v, it->c));         G[it->v].push_back(make_pair(it->u, it->c));       }     }     for (int i = 1; i <= n; i++) {       getd(i);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (d[i][j] != f[i][j]) {           puts( NO );           return 0;         }     puts( YES );     return 0;   }   