結果

問題 No.1 道のショートカット
ユーザー takakintakakin
提出日時 2020-04-11 22:35:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,130 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 33,660 KB
最終ジャッジ日時 2023-09-22 13:41:38
合計ジャッジ時間 6,244 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,444 KB
testcase_01 AC 17 ms
8,520 KB
testcase_02 AC 17 ms
8,452 KB
testcase_03 AC 17 ms
8,316 KB
testcase_04 AC 17 ms
8,324 KB
testcase_05 AC 17 ms
8,416 KB
testcase_06 AC 17 ms
8,480 KB
testcase_07 AC 17 ms
8,408 KB
testcase_08 AC 273 ms
24,860 KB
testcase_09 AC 161 ms
17,748 KB
testcase_10 AC 90 ms
13,276 KB
testcase_11 AC 168 ms
17,520 KB
testcase_12 AC 449 ms
31,172 KB
testcase_13 AC 417 ms
30,572 KB
testcase_14 AC 37 ms
9,804 KB
testcase_15 AC 19 ms
8,924 KB
testcase_16 WA -
testcase_17 AC 19 ms
8,820 KB
testcase_18 AC 36 ms
9,744 KB
testcase_19 AC 66 ms
11,788 KB
testcase_20 AC 70 ms
11,996 KB
testcase_21 WA -
testcase_22 AC 58 ms
11,160 KB
testcase_23 AC 411 ms
29,124 KB
testcase_24 AC 502 ms
33,660 KB
testcase_25 AC 154 ms
16,776 KB
testcase_26 AC 111 ms
14,080 KB
testcase_27 AC 328 ms
25,500 KB
testcase_28 AC 22 ms
8,800 KB
testcase_29 AC 54 ms
10,928 KB
testcase_30 AC 24 ms
8,800 KB
testcase_31 AC 44 ms
10,352 KB
testcase_32 AC 196 ms
20,316 KB
testcase_33 AC 128 ms
16,412 KB
testcase_34 AC 244 ms
22,332 KB
testcase_35 AC 23 ms
8,656 KB
testcase_36 AC 47 ms
10,520 KB
testcase_37 WA -
testcase_38 AC 22 ms
9,016 KB
testcase_39 WA -
testcase_40 AC 25 ms
9,000 KB
testcase_41 AC 18 ms
8,576 KB
testcase_42 AC 16 ms
8,412 KB
testcase_43 AC 21 ms
9,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
c=int(input())
v=int(input())
S=[int(i) for i in input().split()]
T=[int(i) for i in input().split()]
Y=[int(i) for i in input().split()]
M=[int(i) for i in input().split()]
nc=n*(c+1)
edge = [[] for i in range(nc)]
for i in range(v):
  s,t,y,m=S[i],T[i],Y[i],M[i]
  for j in range(y,c+1):
    edge[s-1+j*n].append(m*10**6+t-1+(j-y)*n)
    edge[t-1+j*n].append(m*10**6+s-1+(j-y)*n)

import heapq
def dijkstra_heap(s):
  d=[float("inf")]*nc
  used=[True]*nc
  d[s]=0
  used[s]=False
  edgelist=[]
  for e in edge[s]:
    heapq.heappush(edgelist,e)
  while edgelist:
    minedge=heapq.heappop(edgelist)
    minedge_cost=minedge//(10**6)
    minedge_v=minedge%(10**6)
    if not used[minedge_v]:
      continue
    d[minedge_v] = minedge_cost
    used[minedge_v] = False
    for e in edge[minedge_v]:
      e_cost=e//(10**6)
      e_v=e%(10**6)
      if used[e_v]:
        heapq.heappush(edgelist,e+minedge_cost*10**6)
  return d
D=dijkstra_heap(n*c)
ans=D[n-1]
for i in range(c):
  ans=min(ans,D[n-1+(i+1)*n])
if ans==float("inf"):
  print(-1)
else:
  print(ans)
0