結果
問題 | No.848 なかよし旅行 |
ユーザー |
![]() |
提出日時 | 2022-12-01 10:56:38 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,035 bytes |
コンパイル時間 | 188 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 103,296 KB |
最終ジャッジ日時 | 2024-04-17 02:00:29 |
合計ジャッジ時間 | 6,363 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 488 ms
103,296 KB |
testcase_01 | AC | 36 ms
53,632 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 33 ms
52,992 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 34 ms
53,248 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 230 ms
83,776 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 123 ms
78,476 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 33 ms
52,480 KB |
testcase_25 | WA | - |
testcase_26 | AC | 36 ms
52,352 KB |
testcase_27 | AC | 34 ms
52,352 KB |
testcase_28 | AC | 37 ms
52,864 KB |
testcase_29 | AC | 33 ms
52,736 KB |
ソースコード
from heapq import heappop, heappush INF = float('inf') def dijkstra(s, n): dist = [INF] * n hq = [(0, s)] # (distance, node) dist[s] = 0 seen = [False] * n while hq: dis, v = heappop(hq) if dist[v] < dis: continue seen[v] = True for to, cost in G[v]: if seen[to] == False and dist[v] + cost < dist[to]: dist[to] = dist[v] + cost heappush(hq, (dist[to], to)) return dist N, M, P, Q, T = map(int, input().split()) G = [list() for _ in range(N)] for i in range(M): a, b, c = map(int, input().split()) a-=1;b-=1 G[a].append((b,c)) G[b].append((a,c)) dis_0 = dijkstra(0,N) dis_p = dijkstra(P-1,N) dis_q = dijkstra(Q-1,N) if max(dis_p[0]*2,dis_q[0]*2)>T: exit(print(-1)) if 2*min(dis_p[0],dis_q[0])+2*dis_p[Q-1]<=T or dis_p[0]+dis_q[0]+dis_p[Q-1]<=T: exit(print(T)) res = 0 for i in range(N): if 2*dis_0[i]+2*max(dis_p[i],dis_q[i])<=T: res = max(res,T-2*max(dis_p[i],dis_q[i])) print(res)