Submission #1691830


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):
    v.append(list(map(int, input().split(" "))))

print(solve(n, v))

Submission Info

Submission Time
Task D - Restoring Road Network
User lanuvas
Language Python (3.4.3)
Score 0
Code Size 866 Byte
Status TLE
Exec Time 2104 ms
Memory 6772 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 2104 ms 6644 KB
02.txt TLE 2104 ms 6644 KB
03.txt TLE 2104 ms 6644 KB
04.txt TLE 2104 ms 6644 KB
05.txt TLE 2104 ms 6644 KB
06.txt TLE 2104 ms 6644 KB
07.txt AC 89 ms 6644 KB
08.txt TLE 2104 ms 6772 KB
09.txt TLE 2104 ms 6644 KB
10.txt AC 145 ms 6644 KB
11.txt AC 60 ms 6644 KB
12.txt AC 39 ms 6644 KB
13.txt AC 18 ms 3064 KB
subtask0_0.txt AC 17 ms 3064 KB
subtask0_1.txt AC 17 ms 3064 KB
subtask0_2.txt AC 17 ms 3064 KB
subtask0_3.txt AC 18 ms 3064 KB