func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   inline void amax(T &x, U y) {     if (x < y) x = y;   }   struct UnionFind {     vector<int> data;     UnionFind(int size_) : data(size_, -1) {}     bool unionSet(int x, int y) {       x = root(x);       y = root(y);       if (x != y) {         if (data[y] < data[x]) swap(x, y);         data[x] += data[y];         data[y] = x;       }       return x != y;     }     bool findSet(int x, int y) { return root(x) == root(y); }     int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }     int size(int x) { return -data[root(x)]; }   };   struct Edge {     int x, y;     int w;     Edge() {}     Edge(int x_, int y_, int w_) : x(x_), y(y_), w(w_) {}   };   bool operator<(const Edge &a, const Edge &b) { return a.w < b.w; }   vector<vector<int> > g;   vector<long long> dist;   vector<vector<int> > d;   void dfs(int i, int p, long long t) {     dist[i] = t;     for (typeof((g[i]).begin()) j = ((g[i]).begin()); j != (g[i]).end(); ++j)       if (*j != p) dfs(*j, i, t + d[i][*j]);   }   int main() {     int n;     scanf( %d , &n);     d.assign(n, vector<int>(n));     for (int(i) = 0; (i) < (int)(n); ++(i))       for (int(j) = 0; (j) < (int)(n); ++(j)) scanf( %d , &d[i][j]);     bool ok = true;     for (int(i) = 0; (i) < (int)(n); ++(i))       for (int(j) = 0; (j) < (int)(i); ++(j)) {         ok &= d[i][j] == d[j][i];         ok &= d[i][j] > 0;       }     for (int(i) = 0; (i) < (int)(n); ++(i)) ok &= d[i][i] == 0;     if (!ok) {       puts( NO );       return 0;     }     vector<Edge> edges;     edges.reserve(n * (n - 1) / 2);     for (int(i) = 0; (i) < (int)(n); ++(i))       for (int(j) = 0; (j) < (int)(i); ++(j))         edges.push_back(Edge(i, j, d[i][j]));     sort(edges.begin(), edges.end());     UnionFind uf(n);     g.assign(n, vector<int>());     for (int i = 0; i < (int)edges.size(); i++) {       int x = edges[i].x, y = edges[i].y;       if (uf.unionSet(x, y)) {         g[x].push_back(y);         g[y].push_back(x);       }     }     dist.resize(n);     for (int(i) = 0; (i) < (int)(n); ++(i)) {       dfs(i, -1, 0);       for (int(j) = 0; (j) < (int)(n); ++(j)) ok &= dist[j] == d[i][j];     }     puts(ok ?  YES  :  NO );     return 0;   }   