結果
問題 | No.1320 Two Type Min Cost Cycle |
ユーザー | Navier_Boltzmann |
提出日時 | 2024-07-06 16:03:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,429 ms / 2,000 ms |
コード長 | 1,675 bytes |
コンパイル時間 | 196 ms |
コンパイル使用メモリ | 82,472 KB |
実行使用メモリ | 108,280 KB |
最終ジャッジ日時 | 2024-07-06 16:04:10 |
合計ジャッジ時間 | 17,343 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
58,128 KB |
testcase_01 | AC | 42 ms
56,152 KB |
testcase_02 | AC | 40 ms
56,232 KB |
testcase_03 | AC | 38 ms
56,836 KB |
testcase_04 | AC | 39 ms
56,076 KB |
testcase_05 | AC | 47 ms
68,768 KB |
testcase_06 | AC | 50 ms
69,332 KB |
testcase_07 | AC | 126 ms
100,424 KB |
testcase_08 | AC | 214 ms
78,360 KB |
testcase_09 | AC | 1,017 ms
90,564 KB |
testcase_10 | AC | 144 ms
108,100 KB |
testcase_11 | AC | 846 ms
86,476 KB |
testcase_12 | AC | 317 ms
79,412 KB |
testcase_13 | AC | 558 ms
80,972 KB |
testcase_14 | AC | 102 ms
77,400 KB |
testcase_15 | AC | 148 ms
108,280 KB |
testcase_16 | AC | 91 ms
77,480 KB |
testcase_17 | AC | 94 ms
90,228 KB |
testcase_18 | AC | 94 ms
90,252 KB |
testcase_19 | AC | 339 ms
88,672 KB |
testcase_20 | AC | 92 ms
77,384 KB |
testcase_21 | AC | 601 ms
80,672 KB |
testcase_22 | AC | 39 ms
56,384 KB |
testcase_23 | AC | 39 ms
57,312 KB |
testcase_24 | AC | 39 ms
57,380 KB |
testcase_25 | AC | 40 ms
56,640 KB |
testcase_26 | AC | 39 ms
55,968 KB |
testcase_27 | AC | 38 ms
56,048 KB |
testcase_28 | AC | 139 ms
77,264 KB |
testcase_29 | AC | 259 ms
99,692 KB |
testcase_30 | AC | 49 ms
65,556 KB |
testcase_31 | AC | 92 ms
79,816 KB |
testcase_32 | AC | 39 ms
56,428 KB |
testcase_33 | AC | 524 ms
80,040 KB |
testcase_34 | AC | 348 ms
78,488 KB |
testcase_35 | AC | 87 ms
76,908 KB |
testcase_36 | AC | 61 ms
73,088 KB |
testcase_37 | AC | 55 ms
69,760 KB |
testcase_38 | AC | 95 ms
77,012 KB |
testcase_39 | AC | 81 ms
77,020 KB |
testcase_40 | AC | 40 ms
57,064 KB |
testcase_41 | AC | 40 ms
56,668 KB |
testcase_42 | AC | 38 ms
56,416 KB |
testcase_43 | AC | 154 ms
104,264 KB |
testcase_44 | AC | 132 ms
92,280 KB |
testcase_45 | AC | 1,429 ms
89,424 KB |
testcase_46 | AC | 89 ms
79,812 KB |
testcase_47 | AC | 446 ms
79,068 KB |
testcase_48 | AC | 550 ms
103,632 KB |
testcase_49 | AC | 91 ms
77,796 KB |
testcase_50 | AC | 42 ms
57,308 KB |
testcase_51 | AC | 44 ms
56,624 KB |
testcase_52 | AC | 182 ms
77,532 KB |
testcase_53 | AC | 137 ms
77,836 KB |
testcase_54 | AC | 472 ms
107,528 KB |
testcase_55 | AC | 508 ms
103,816 KB |
testcase_56 | AC | 490 ms
107,204 KB |
testcase_57 | AC | 1,051 ms
86,940 KB |
testcase_58 | AC | 1,052 ms
86,792 KB |
testcase_59 | AC | 1,050 ms
87,060 KB |
ソースコード
# import pypyjit # pypyjit.set_param("max_unroll_recursion=-1") from collections import * from functools import * from itertools import * from heapq import * import sys, math # sys.setrecursionlimit(10**4) input = sys.stdin.readline INF = (1<<60) def dijkstra(s,e): N = len(e) dist = [INF]*N dist[s]=0 h = [] bef = [-1]*N heappush(h,s) while h: nw,v = divmod(heappop(h),N) if dist[v]!=nw: continue for iv,ic in e[v]: nc = ic + nw if nc < dist[iv]: bef[iv] = v dist[iv] = nc heappush(h,nc*N + iv) return dist,bef def answer1(): N,M = map(int,input().split()) e = [[] for _ in range(N)] for _ in range(M): u,v,w = map(int,input().split()) u -= 1 v -= 1 e[u].append((v,w)) ans = INF d = [dijkstra(s,e)[0] for s in range(N)] for i in range(N-1): for j in range(i+1,N): ans = min(ans,d[i][j] + d[j][i]) if ans==INF: print(-1) else: print(ans) return def answer0(): N,M = map(int,input().split()) e = [[] for _ in range(N)] for _ in range(M): u,v,w = map(int,input().split()) u -= 1 v -= 1 e[u].append((v,w)) e[v].append((u,w)) ans = INF for r in range(N): dist,bef = dijkstra(r,e) for i in range(N): for j,wj in e[i]: if (bef[i]!=j)&(bef[j]!=i): ans = min(ans,dist[i]+dist[j]+wj) if ans==INF: print(-1) else: print(ans) T = int(input()) if T==1: answer1() else: answer0()