Submission #1691840


Source Code Expand

def shortcutable(v, n, x, y):
    a = v[(x, y)]
    can_prunning = False
    for z in range(n):
        if not z in (x,y):
            b = v[(x,z)]
            c = v[(z,y)]
            #print(x,y,z,a,b,c)
            if (b + c) < a:
                return -1
            if (b + c) == a:
                can_prunning = True
    if can_prunning:
        #print(x,y,a)
        return 0
    else:
        return a

def solve(n, v):
    shortcuts = []
    total = 0
    for x in range(n):
        for y in range(x+1,n):
            result = shortcutable(v, n, x, y)
            if result < 0:
                return -1
            else:
                total += result
            #print(x,y,total)
    
    return total

n = int(input())
v = {}
for i in range(n):
    for (j, distance) in enumerate(map(int, input().split(" "))):
        v[(i,j)] = distance

print(solve(n, v))

Submission Info

Submission Time
Task D - Restoring Road Network
User lanuvas
Language Python (3.4.3)
Score 0
Code Size 916 Byte
Status TLE
Exec Time 2105 ms
Memory 21092 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 4
AC × 9
TLE × 8
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 TLE 2105 ms 21092 KB
02.txt TLE 2105 ms 21092 KB
03.txt TLE 2105 ms 21088 KB
04.txt TLE 2105 ms 21092 KB
05.txt TLE 2105 ms 21088 KB
06.txt TLE 2105 ms 21088 KB
07.txt AC 180 ms 21088 KB
08.txt TLE 2105 ms 21088 KB
09.txt TLE 2105 ms 21088 KB
10.txt AC 339 ms 21088 KB
11.txt AC 153 ms 21088 KB
12.txt AC 131 ms 21092 KB
13.txt AC 19 ms 3064 KB
subtask0_0.txt AC 20 ms 3064 KB
subtask0_1.txt AC 18 ms 3064 KB
subtask0_2.txt AC 19 ms 3064 KB
subtask0_3.txt AC 18 ms 3064 KB