Submission #1982999


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int t;
  cin >> t;
  while(t--) {
    int n;
    cin >> n;
    int a[33][33];
    int b[33][33];
    rep(i, n) rep(j, n) {
      cin >> a[i][j];
      if(a[i][j] == -1) a[i][j] = inf;
      b[i][j] = a[i][j];
    }
    rep(i, n) b[i][i] = 0;
    rep(i, n) rep(j, n) rep(k, n) {
      chmin(b[j][k], b[j][i]+b[i][k]);
    }
    /*
    rep(i, n) {
      rep(j, n) cout << b[i][j] << " ";
      cout << endl;
    }
    */
    bool flag = true;
    rep(i, n) rep(j, n) {
      if(a[i][j] != b[i][j]) flag = false;
    }
    cout << (flag ? "YES" : "NO") << endl;
  }

  return 0;
}

Submission Info

Submission Time
Task C - 最短経路
User ukuku09
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1275 Byte
Status AC
Exec Time 4 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 41
Set Name Test Cases
All 00_sample.txt, 10_random_00.txt, 10_random_01.txt, 10_random_02.txt, 10_random_03.txt, 10_random_04.txt, 10_random_05.txt, 10_random_06.txt, 10_random_07.txt, 10_random_08.txt, 10_random_09.txt, 10_random_10.txt, 10_random_11.txt, 10_random_12.txt, 10_random_13.txt, 10_random_14.txt, 10_random_15.txt, 10_random_16.txt, 10_random_17.txt, 10_random_18.txt, 10_random_19.txt, 10_random_20.txt, 10_random_21.txt, 10_random_22.txt, 10_random_23.txt, 10_random_24.txt, 10_random_25.txt, 10_random_26.txt, 10_random_27.txt, 10_random_28.txt, 10_random_29.txt, 22_random_30.txt, 22_random_31.txt, 23_coplete_32.txt, 23_coplete_33.txt, 24_path_34.txt, 24_path_35.txt, 25_tree_36.txt, 25_tree_37.txt, 26_noedge_38.txt, 27_dot_39.txt
Case Name Status Exec Time Memory
00_sample.txt AC 1 ms 256 KB
10_random_00.txt AC 4 ms 256 KB
10_random_01.txt AC 4 ms 256 KB
10_random_02.txt AC 4 ms 256 KB
10_random_03.txt AC 4 ms 256 KB
10_random_04.txt AC 4 ms 256 KB
10_random_05.txt AC 4 ms 256 KB
10_random_06.txt AC 4 ms 256 KB
10_random_07.txt AC 4 ms 256 KB
10_random_08.txt AC 4 ms 256 KB
10_random_09.txt AC 4 ms 256 KB
10_random_10.txt AC 4 ms 256 KB
10_random_11.txt AC 4 ms 256 KB
10_random_12.txt AC 4 ms 256 KB
10_random_13.txt AC 4 ms 256 KB
10_random_14.txt AC 4 ms 256 KB
10_random_15.txt AC 4 ms 256 KB
10_random_16.txt AC 4 ms 256 KB
10_random_17.txt AC 4 ms 256 KB
10_random_18.txt AC 4 ms 256 KB
10_random_19.txt AC 4 ms 256 KB
10_random_20.txt AC 4 ms 256 KB
10_random_21.txt AC 4 ms 256 KB
10_random_22.txt AC 4 ms 256 KB
10_random_23.txt AC 4 ms 256 KB
10_random_24.txt AC 4 ms 256 KB
10_random_25.txt AC 4 ms 256 KB
10_random_26.txt AC 4 ms 256 KB
10_random_27.txt AC 4 ms 256 KB
10_random_28.txt AC 4 ms 256 KB
10_random_29.txt AC 4 ms 256 KB
22_random_30.txt AC 4 ms 256 KB
22_random_31.txt AC 4 ms 256 KB
23_coplete_32.txt AC 4 ms 256 KB
23_coplete_33.txt AC 4 ms 256 KB
24_path_34.txt AC 4 ms 256 KB
24_path_35.txt AC 4 ms 256 KB
25_tree_36.txt AC 4 ms 256 KB
25_tree_37.txt AC 4 ms 256 KB
26_noedge_38.txt AC 4 ms 256 KB
27_dot_39.txt AC 1 ms 256 KB