結果
問題 | No.2712 Play more! |
ユーザー | RYOH2718 |
提出日時 | 2024-03-31 15:16:43 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,033 bytes |
コンパイル時間 | 173 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 77,376 KB |
最終ジャッジ日時 | 2024-03-31 15:16:46 |
合計ジャッジ時間 | 3,127 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
53,460 KB |
testcase_01 | AC | 41 ms
53,460 KB |
testcase_02 | AC | 40 ms
53,460 KB |
testcase_03 | AC | 40 ms
53,460 KB |
testcase_04 | WA | - |
testcase_05 | AC | 40 ms
53,460 KB |
testcase_06 | AC | 41 ms
53,460 KB |
testcase_07 | AC | 95 ms
77,376 KB |
testcase_08 | AC | 87 ms
76,480 KB |
testcase_09 | AC | 88 ms
77,120 KB |
testcase_10 | WA | - |
testcase_11 | AC | 52 ms
63,368 KB |
testcase_12 | AC | 60 ms
65,824 KB |
testcase_13 | AC | 44 ms
55,608 KB |
testcase_14 | AC | 88 ms
77,120 KB |
testcase_15 | AC | 62 ms
68,016 KB |
testcase_16 | AC | 44 ms
55,608 KB |
testcase_17 | AC | 41 ms
53,460 KB |
testcase_18 | AC | 52 ms
63,368 KB |
testcase_19 | AC | 43 ms
55,608 KB |
testcase_20 | AC | 54 ms
63,368 KB |
testcase_21 | AC | 43 ms
55,608 KB |
testcase_22 | AC | 62 ms
68,016 KB |
testcase_23 | AC | 42 ms
53,460 KB |
testcase_24 | AC | 44 ms
55,608 KB |
testcase_25 | AC | 39 ms
53,460 KB |
testcase_26 | AC | 56 ms
63,332 KB |
testcase_27 | AC | 66 ms
68,016 KB |
testcase_28 | AC | 65 ms
67,888 KB |
testcase_29 | AC | 46 ms
55,608 KB |
testcase_30 | AC | 88 ms
77,248 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
ソースコード
# 標準入力された値を整数に変換する def INT(): return int(input()) # 標準入力された複数の値を整数に変換する def MI(): return map(int, input().split()) # 標準入力された複数の値を整数のリストに変換する def LI(): return list(map(int, input().split())) class UnionFind: def __init__(self, N): self.root = [_ for _ in range(N)] self.rank = [0] * N self.size = [1] * N def find(self, x): if self.root[x] == x: return x else: # 根を予め取得し,経路圧縮する self.root[x] = self.find(self.root[x]) return self.root[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return else: if self.rank[x] > self.rank[y]: self.size[x] += self.size[y] self.root[y] = x else: self.size[y] += self.size[x] self.root[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def same(self, x, y): return self.find(x) == self.find(y) def getSizeOfSet(self, x): return self.size[self.find(x)] import heapq def dijkstra(n, G, start=0): INF = 10**18 dist = [INF] * n dist[start] = 0 pq = [] heapq.heappush(pq, (0, start)) visited = [False] * n while pq: now = heapq.heappop(pq)[1] visited[now] = True for nxt, cost in G[now]: if dist[nxt] > dist[now] + cost and not visited[nxt]: dist[nxt] = dist[now] + cost heapq.heappush(pq, (dist[now] + cost, nxt)) return dist N, M = MI() A = LI() G = [[] for i in range(N)] dsu = UnionFind(N) for _ in range(M): a, b, c = MI() a -= 1 b -= 1 G[a].append((b, A[b] - c)) if dsu.same(a, b): print("inf") exit(0) dsu.union(a, b) dist = dijkstra(N, G) print(dist[-1] + A[0])