Language: C++

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

struct data {
    long long d;
    int i;
    int j;
};

std::vector<sdt::pair<int, long long> > edge[304];

long long A[304][304];
long lond D[304][304];

int main(){
    int N:
    scanf("%d", &N);
    for (int i=0; i<N; i++){
        for (int j=0; j<N; j++){
            scanf("%lld", &A[i][j]);
        }
    }
    std::vector<data> vec;
    for (int i=0; i<N: i++){
        for (int j=i+1; j<N;j++){
            vec.push_back((data){A[i][j], i, j});
        }
    }
    std::sort(vec.begin(), vec.end());
    for (auto &entry : vec){
        std::vector<int> dist(304, -1);
        long long d = vec.d;
        int i = vec.i;
        int j = vec.j;
        dist[i]=0;
        std::priority_queue<std::pair<long long, int> > queue;
        queue.push(std::make_pair(0, i));
        while(queue.size()>0){
            long long d = queue.top().first;
            int v = queue.top().second;
            queue.pop();
            if (dist[v]!=-1 && dist[v]<d) continue;
            for (auto cont : edge[v]){
                int vv = cont.first;
                long long dd = cont.second;
                if (dist[vv]!=-1 && dist[vv]>d+dd) continue;
                dist[vv] = d+dd;
                queue.push(std::make_pair(d+dd, vv));
            }
        }
        if (dist[j]==-1 || dist[j]>d){
            edge[i].push_back(j, d);
            edge[j].push_back(i, 0);
        } else if (dist[j]<d){
            printf("-1");
            return 0;
        }
    }
    for (int i=0; i<304; i++){
        for (int j=0; j<304; j++){
            D[i][j]=1e18;
        }
    }
    for (int i=0; i<304; i++){
        for (auto &entry: edge[i]){
            D[i][entry.first] = entry.second;
        }
    }  
    for (int k=0; k<304; k++){
        for (int i=0; i<304; i++){
            for (int j=0; j<304; j++){
                D[i][j] = std::min(D[i][j], D[i][k]+D[k][j]);
            }
        }
    }
    long long ans = 0;
    for (int i=0; i<N; i++){
        for (int j=i+1; j<N; j++){
                if (D[i][j]!=A[i][j]){
                    printf("-1\n");
                }
                ans += D[i][j];
            }
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Compiler output:
a.cc:21:13: error: 'sdt' was not declared in this scope; did you mean 'std'?
   21 | std::vector<sdt::pair<int, long long> > edge[304];
      |             ^~~
      |             std
a.cc:21:39: error: template argument 1 is invalid
   21 | std::vector<sdt::pair<int, long long> > edge[304];
      |                                       ^
a.cc:21:39: error: template argument 2 is invalid
a.cc:24:11: error: expected initializer before 'D'
   24 | long lond D[304][304];
      |           ^
a.cc: In function 'int main()':
a.cc:27:10: error: found ':' in nested-name-specifier, expected '::'
   27 |     int N:
      |          ^
      |          ::
a.cc:27:9: error: 'N' has not been declared
   27 |     int N:
      |         ^
a.cc:28:10: error: qualified-id in declaration before '(' token
   28 |     scanf("%d", &N);
      |          ^
a.cc:29:21: error: 'N' was not declared in this scope
   29 |     for (int i=0; i<N; i++){
      |                     ^
a.cc:35:19: warning: range-based 'for' loops with initializer only available with '-std=c++20' or '-std=gnu++20' [-Wc++20-extensions]
   35 |     for (int i=0; i<N: i++){
      |                   ^
a.cc:35:22: error: found ':' in nested-name-specifier, expected '::'
   35 |     for (int i=0; i<N: i++){
      |                      ^
      |                      ::
a.cc:35:21: error: 'N' has not been declared
   35 |     for (int i=0; i<N: i++){
      |                     ^
a.cc:40:14: error: could not convert 'std::sort<__gnu_cxx::__normal_iterator<data*, vector<data> > >(vec.std::vector<data>::begin(), vec.std::vector<data>::end())' from 'void' to 'bool'
   40 |     std::sort(vec.begin(), vec.end());
      |     ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
      |              |
      |              void
a.cc:41:5: error: expected primary-expression before 'for'
   41 |     for (auto &entry : vec){
      |     ^~~
a.cc:40:39: error: expected ')' before 'for'
   40 |     std::sort(vec.begin(), vec.end());
      |                                       ^
      |                                       )
   41 |     for (auto &entry : vec){
      |     ~~~                                
a.cc:35:9: note: to match this '('
   35 |     for (int i=0; i<N: i++){
      |         ^
a.cc:43:27: error: 'class std::vector<data>' has no member named 'd'
   43 |         long long d = vec.d;
      |                           ^
a.cc:44:21: error: 'class std::vector<data>' has no member named 'i'
   44 |         int i = vec.i;
      |                     ^
a.cc:45:21: error: 'class std::vector<data>' has no member named 'j'
   45 |         int j = vec.j;
      |                     ^
a.cc:54:36: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   54 |             for (auto cont : edge[v]){
      |                                    ^
      |                                    std::begin
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:54:36: error: 'end' was not declared in this scope; did you mean 'std::end'?
   54 |             for (auto cont : edge[v]){
      |                                    ^
      |                                    std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
a.cc:63:21: error: request for member 'push_back' in 'edge[i]', which is of non-class type 'int'
   63 |             edge[i].push_back(j, d);
      |                     ^~~~~~~~~
a.cc:64:21: error: request for member 'push_back' in 'edge[j]', which is of non-class type 'int'
   64 |             edge[j].push_back(i, 0);
      |                     ^~~~~~~~~
a.cc:72:13: error: 'D' was not declared in this scope
   72 |             D[i][j]=1e18;
      |             ^
a.cc:76:33: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   76 |         for (auto &entry: edge[i]){
      |                                 ^
      |                                 std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:76:33: error: 'end' was not declared in this scope; did you mean 'std::end'?
   76 |         for (auto &entry: edge[i]){
      |                                 ^
      |                                 std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
a.cc:77:13: error: 'D' was not declared in this scope
   77 |             D[i][entry.first] = entry.second;
      |             ^
a.cc:83:17: error: 'D' was not declared in this scope
   83 |                 D[i][j] = std::min(D[i][j], D[i][k]+D[k][j]);
      |                 ^
a.cc:88:21: error: 'N' was not declared in this scope
   88 |     for (int i=0; i<N; i++){
      |                     ^
a.cc:90:21: error: 'D' was not declared in this scope
   90 |                 if (D[i][j]!=A[i][j]){
      |                     ^
a.cc:93:24: error: 'D' was not declared in this scope
   93 |                 ans += D[i][j];
      |                        ^
a.cc: At global scope:
a.cc:97:10: error: 'cout' in namespace 'std' does not name a type
   97 |     std::cout << ans << std::endl;
      |          ^~~~
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:98:5: error: expected unqualified-id before 'return'
   98 |     return 0;
      |     ^~~~~~
a.cc:99:1: error: expected declaration before '}' token
   99 | }
      | ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/string:51:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = __gnu_cxx::__normal_iterator<data*, std::vector<data> >; _Iterator2 = __gnu_cxx::__normal_iterator<data*, std::vector<data> >]':
/usr/include/c++/14/bits/stl_algo.h:1777:14:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<data*, vector<data> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
 1777 |           if (__comp(__i, __first))
      |               ~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<data*, vector<data> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<data*, vector<data> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4772:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<data*, vector<data> >]'
 4772 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter());
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:40:14:   required from here
   40 |     std::sort(vec.begin(), vec.end());
      |     ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:45:23: error: no match for 'operator<' (operand types are 'data' and 'data')
   45 |       { return *__it1 < *__it2; }
      |                ~~~~~~~^~~~~~~~
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:1241:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)'
 1241 |     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1241:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:45:23: note:   'data' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>'
   45 |       { return *__it1 < *__it2; }
      |                ~~~~~~~^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1249:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)'
 1249 |     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1249:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:45:23: note:   'data' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>'
   45 |       { return *__it1 < *__it2; }
      |                ~~~~~~~^~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_less_iter::operator()(_Value&, _Iterator) const [with _Value =