結果
問題 | No.2915 辺更新価値最大化 |
ユーザー | Shirotsume |
提出日時 | 2024-07-29 19:41:38 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,996 bytes |
コンパイル時間 | 304 ms |
コンパイル使用メモリ | 81,988 KB |
実行使用メモリ | 87,472 KB |
最終ジャッジ日時 | 2024-07-29 20:31:12 |
合計ジャッジ時間 | 10,017 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
61,696 KB |
testcase_01 | AC | 47 ms
56,064 KB |
testcase_02 | AC | 48 ms
56,064 KB |
testcase_03 | AC | 48 ms
56,576 KB |
testcase_04 | AC | 53 ms
62,592 KB |
testcase_05 | AC | 53 ms
62,208 KB |
testcase_06 | AC | 56 ms
64,000 KB |
testcase_07 | AC | 195 ms
78,652 KB |
testcase_08 | AC | 222 ms
78,680 KB |
testcase_09 | AC | 248 ms
78,464 KB |
testcase_10 | AC | 263 ms
78,592 KB |
testcase_11 | AC | 245 ms
78,388 KB |
testcase_12 | AC | 245 ms
78,464 KB |
testcase_13 | AC | 384 ms
79,716 KB |
testcase_14 | AC | 359 ms
78,760 KB |
testcase_15 | AC | 501 ms
80,140 KB |
testcase_16 | AC | 467 ms
79,880 KB |
testcase_17 | AC | 358 ms
79,744 KB |
testcase_18 | AC | 405 ms
79,972 KB |
testcase_19 | AC | 358 ms
79,864 KB |
testcase_20 | AC | 432 ms
80,240 KB |
testcase_21 | AC | 318 ms
79,452 KB |
testcase_22 | AC | 160 ms
78,544 KB |
testcase_23 | AC | 131 ms
78,080 KB |
testcase_24 | AC | 127 ms
77,824 KB |
testcase_25 | TLE | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
ソースコード
import sys, time, random from collections import deque, Counter, defaultdict input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 61 - 1 mod = 998244353 def Dijkstra(s, graph): INF = 2 ** 61 - 1 import heapq n = len(graph) dist = [INF] * n dist[s] = 0 bef = [0] * n bef[s] = s hq = [(0, s)] heapq.heapify(hq) while hq: c, now = heapq.heappop(hq) if c > dist[now]: continue for to, cost in graph[now]: if dist[now] + cost < dist[to]: dist[to] = cost + dist[now] bef[to] = now heapq.heappush(hq, (dist[to], + to)) return dist, bef n, m, q = mi() assert 1 <= n <= 10 ** 3 and 1 <= m <= 10 ** 3 and 1 <= q <= 10 ** 3 graph = [[] for _ in range(n)] EDGE = [] for _ in range(m): u, v, c = mi() assert 1 <= u <= n and 1 <= v <= n and -10 ** 3 <= c <= 10 ** 3 assert u != v u -= 1 v -= 1 c *= -1 EDGE.append((u, v, c)) graph[u].append((v, c)) #ベルマンフォード法 dist = [inf] * n dist[0] = 0 for _ in range(n): for j in range(n): for to, c in graph[j]: if dist[to] > dist[j] + c: dist[to] = dist[j] + c for i in range(n): for to, c in graph[j]: assert dist[to] <= dist[j] + c graph2 = [[] for _ in range(n)] EDGE2 = [] d1 = dist[n - 1] for u, v, c in EDGE: EDGE2.append((u, v, c + dist[v] - dist[u])) graph2[u].append((v, c + dist[v] - dist[u])) onoff = [1] * m E = li() for e in E: assert 1 <= e <= m e -= 1 if onoff[e]: onoff[e] = 0 graph2[EDGE2[e][0]].remove((EDGE2[e][1], EDGE2[e][2])) else: onoff[e] = 1 graph2[EDGE2[e][0]].append((EDGE2[e][1], EDGE2[e][2])) dist, bef = Dijkstra(0, graph2) if dist[n - 1] == inf: print('NaN') else: print(-(dist[n - 1] - d1))