#include #include using namespace std; using ll = long long int; using u64 = unsigned long long; using pll = pair; // #include // using namespace atcoder; #define REP(i, a, b) for (ll i = (a); i < (b); i++) #define REPrev(i, a, b) for (ll i = (a); i >= (b); i--) #define ALL(coll) (coll).begin(), (coll).end() #define SIZE(v) ((ll)((v).size())) #define REPOUT(i, a, b, exp, sep) REP(i, (a), (b)) cout << (exp) << (i + 1 == (b) ? "" : (sep)); cout << "\n" // @@ !! LIM(forall) // ---- inserted library file forall.cc #define EX_REP_LL(i, from, to) for (ll i = (from); i < (to); i++) #define EX_REP_RB(x, coll) for (auto x : coll) #define EXGEN(rep_part, cond, yes, no_behaviour) ([&]() { rep_part if (cond) return (yes); no_behaviour; }()) #define EXISTS_BASE(rep_part, cond) EXGEN(rep_part, cond, true, return false) #define EXFIND_BASE(rep_part, cond, t) EXGEN(rep_part, cond, t, assert(0)) #define EXFIND_D_BASE(rep_part, cond, t, def) EXGEN(rep_part, cond, t, return def) #define EXISTS(i, from, to, cond) EXISTS_BASE(EX_REP_LL(i, from, to), cond) #define FORALL(i, from, to, cond) (not EXISTS(i, from, to, not (cond))) #define EXFIND(i, from, to, cond) EXFIND_BASE(EX_REP_LL(i, from, to), cond, i) #define EXFIND_D(i, from, to, cond, def) EXFIND_D_BASE(EX_REP_LL(i, from, to), cond, i, def) #define EXISTS_C(x, coll, cond) EXISTS_BASE(EX_REP_RB(x, coll), cond) #define FORALL_C(x, coll, cond) (not EXISTS_C(x, coll, not (cond))) #define EXFIND_C(x, coll, cond) EXFIND_BASE(EX_REP_RB(x, coll), cond, x) #define EXFIND_D_C(x, coll, cond, def) EXFIND_D_BASE(EX_REP_RB(x, coll), cond, x, def) #define COUNT_BASE(rep_part, cond) ([&](){ ll ret = 0; rep_part if (cond) ret++; return ret; }()) #define COUNT(i, from, to, cond) COUNT_BASE(EX_REP_LL(i, from, to), cond) #define COUNT_C(x, coll, cond) COUNT_BASE(EX_REP_RB(x, coll), cond) #define IMPLIES(a, b) (not (a) or (b)) // ---- end forall.cc // @@ !! LIM -- end mark -- int main(/* int argc, char *argv[] */) { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(20); ll N; cin >> N; // @InpGrid(N, N, D) [yEHdkyxN] auto D = vector(N, vector(N, ll())); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { ll v; cin >> v; D[i][j] = v; } // @End [yEHdkyxN] bool b1 = FORALL(i, 0, N, FORALL(j, 0, N, (D[i][j] == 0) == (i == j))); bool b2 = FORALL(i, 0, N, FORALL(j, 0, N, D[i][j] == D[j][i])); bool b3 = FORALL(i, 0, N, FORALL(j, 0, N, FORALL(k, 0, N, D[i][j] <= D[i][k] + D[k][j]))); bool b4 = FORALL(i, 0, N, FORALL(j, 0, N, FORALL(k, 0, N, D[i][j] <= max(D[i][k], D[k][j])))); cout << (b1 and b2 and b3 ? "Yes\n" : "No\n"); cout << (b1 and b2 and b4 ? "Yes\n" : "No\n"); return 0; }