Submission #1871639
Source Code Expand
#include <iostream> #define N_MAX 300 #define INF (2<<21) using namespace std; int N; int E[N_MAX][N_MAX]; int A[N_MAX][N_MAX]; void warshall_floyd(){ for (int k=0; k<N; k++){ for (int i=0; i<N; i++){ for (int j=0; j<N; j++){ if (E[i][j] > E[i][k] + E[k][j]){ E[i][j] = E[i][k] + E[k][j]; } } } } } int main(void){ cin >> N; for (int i=0; i<N; i++){ for (int j=0; j<N; j++){ cin >> E[i][j]; A[i][j] = E[i][j]; } } for (int k=0; k<N; k++){ for (int i=0; i<N; i++){ for (int j=0; j<N; j++){ if(k == i || k == j || i == j || E[i][k] == INF || E[k][j] == INF) continue; if (E[i][j] > E[i][k] + E[k][j]){ cout << "-1" << endl; return 0; } else if (E[i][j] == E[i][k] + E[k][j]){ A[i][j] = INF; } } } } long long int sum = 0; for (int i=0; i<N; i++){ for (int j=0; j<N; j++){ if (A[i][j] != INF) sum += A[i][j]; } } cout << (sum/2) << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Restoring Road Network |
User | blackstone |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 1000 Byte |
Status | AC |
Exec Time | 116 ms |
Memory | 1024 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
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 | 116 ms | 896 KB |
02.txt | AC | 116 ms | 896 KB |
03.txt | AC | 116 ms | 896 KB |
04.txt | AC | 113 ms | 896 KB |
05.txt | AC | 114 ms | 896 KB |
06.txt | AC | 109 ms | 896 KB |
07.txt | AC | 41 ms | 896 KB |
08.txt | AC | 101 ms | 896 KB |
09.txt | AC | 101 ms | 896 KB |
10.txt | AC | 41 ms | 896 KB |
11.txt | AC | 40 ms | 896 KB |
12.txt | AC | 48 ms | 1024 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 |