func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 2005;   const int MOD = 1e9 + 7;   int a[N][N];   vector<pair<int, pair<int, int> > > vv;   int p[N], dist[N][N];   std::vector<pair<int, int> > v[N];   int visit[N];   int root(int x) {     while (x != p[x]) {       p[x] = p[p[x]];       x = p[x];     }     return x;   }   void join(int x, int y) { p[root(y)] = root(x); }   void dfs(int node, int dis, int start) {     visit[node] = start;     if (a[start][node] != dis) {       printf( NO );       exit(0);     }     for (auto i : v[node]) {       if (visit[i.first] != start) {         dfs(i.first, dis + i.second, start);       }     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         scanf( %d , &a[i][j]);         if (a[i][j] && i == j) {           printf( NO );           return 0;         }         if (!a[i][j] && i != j) {           printf( NO );           return 0;         }         if (i < j && a[i][j]) {           vv.push_back({a[i][j], {i, j}});         }       }     }     sort(vv.begin(), vv.end());     int ct = 0;     for (int i = 1; i <= n; i++) p[i] = i;     for (auto i : vv) {       int wt = i.first, l = i.second.first, r = i.second.second;       if (root(l) != root(r)) {         join(l, r);         v[l].push_back({r, wt});         v[r].push_back({l, wt});         ct++;         if (ct == n - 1) break;       }     }     for (int i = 1; i <= n; i++) {       dfs(i, 0, i);     }     printf( YES );     return 0;   }   