init
This commit is contained in:
commit
851751ea87
82 changed files with 2093 additions and 0 deletions
24
3K.py
Normal file
24
3K.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import sys
|
||||
|
||||
data = list(map(int, sys.stdin.read().split()))
|
||||
|
||||
n = data[0]
|
||||
init_ = data[1 : 1 + n * n]
|
||||
queue_to_del = [x - 1 for x in data[1 + n * n :]]
|
||||
ans = []
|
||||
active = [False] * n
|
||||
for step in range(n - 1, -1, -1):
|
||||
k = queue_to_del[step]
|
||||
active[k] = True
|
||||
cur_sum = 0
|
||||
k_row = k * n
|
||||
for i in range(n):
|
||||
i_row = i * n
|
||||
dik = init_[i_row + k]
|
||||
for j in range(n):
|
||||
if dik + init_[k_row + j] < init_[i_row + j]:
|
||||
init_[i_row + j] = dik + init_[k_row + j]
|
||||
if active[i] and active[j]:
|
||||
cur_sum += init_[i_row + j]
|
||||
ans.append(cur_sum)
|
||||
print(" ".join(map(str, reversed(ans))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue