結果

問題 No.2477 Drifting
ユーザー 👑 rin204rin204
提出日時 2023-09-08 20:39:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 575 ms / 2,000 ms
コード長 790 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 145,276 KB
最終ジャッジ日時 2023-09-08 20:40:17
合計ジャッジ時間 8,232 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 547 ms
137,284 KB
testcase_01 AC 370 ms
117,292 KB
testcase_02 AC 547 ms
137,300 KB
testcase_03 AC 358 ms
115,936 KB
testcase_04 AC 212 ms
96,776 KB
testcase_05 AC 373 ms
112,544 KB
testcase_06 AC 575 ms
145,276 KB
testcase_07 AC 560 ms
145,272 KB
testcase_08 AC 535 ms
129,956 KB
testcase_09 AC 333 ms
102,912 KB
testcase_10 AC 346 ms
106,060 KB
testcase_11 AC 353 ms
100,756 KB
testcase_12 AC 300 ms
106,464 KB
testcase_13 AC 72 ms
71,364 KB
testcase_14 AC 70 ms
71,232 KB
testcase_15 AC 70 ms
71,376 KB
testcase_16 AC 310 ms
99,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.readline


n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    u, v, w = map(int, input().split())
    edges[u - 1].append((v - 1, w))

ng = set()
k = int(input())
for _ in range(k):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    c -= 1
    ng.add((a, b, c))

cand = [[] for _ in range(n)]
cand[0] = [(0, 0)]
for l in range(n):
    cand[l].sort(key=lambda x: x[0])
    for d, a in cand[l]:
        nex = []
        for r, w in edges[l]:
            if (a, l, r) in ng:
                nex.append((r, w))
            else:
                cand[r].append((d + w, l))

        edges[l] = nex

ans = 1 << 60
for d, _ in cand[n - 1]:
    ans = min(ans, d)

if ans == 1 << 60:
    print(-1)
else:
    print(ans)
0