Submission #1872067


Source Code Expand

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    int n;
    cin >> n;
    vector<vector<LL>> g(n, vector<LL>(n));
    vector<vector<LL>> cnt(n, vector<LL>(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> g[i][j];
        }
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (g[i][j] > g[i][k] + g[k][j]) {
                    cout << -1 << endl;
                    return 0;
                } else if (g[i][j] == g[i][k] + g[k][j]) cnt[i][j]++;
            }
        }
    }

    LL ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (cnt[i][j] == 2) ans += g[i][j];
        }
    }

    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task D - Restoring Road Network
User takaten
Language C++14 (GCC 5.4.1)
Score 500
Code Size 991 Byte
Status AC
Exec Time 70 ms
Memory 1664 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 17
Set Name Test Cases
Sample subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt
Case Name Status Exec Time Memory
01.txt AC 67 ms 1664 KB
02.txt AC 69 ms 1664 KB
03.txt AC 70 ms 1664 KB
04.txt AC 67 ms 1664 KB
05.txt AC 67 ms 1664 KB
06.txt AC 64 ms 1664 KB
07.txt AC 32 ms 1664 KB
08.txt AC 61 ms 1664 KB
09.txt AC 60 ms 1664 KB
10.txt AC 32 ms 1664 KB
11.txt AC 32 ms 1664 KB
12.txt AC 37 ms 1664 KB
13.txt AC 1 ms 256 KB
subtask0_0.txt AC 1 ms 256 KB
subtask0_1.txt AC 1 ms 256 KB
subtask0_2.txt AC 1 ms 256 KB
subtask0_3.txt AC 1 ms 256 KB