結果

問題 No.2712 Play more!
ユーザー hato336hato336
提出日時 2024-03-31 14:20:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,712 ms / 2,000 ms
コード長 1,204 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 92,352 KB
最終ジャッジ日時 2024-04-03 12:09:50
合計ジャッジ時間 17,392 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
84,920 KB
testcase_01 AC 126 ms
84,920 KB
testcase_02 AC 127 ms
84,920 KB
testcase_03 AC 124 ms
84,920 KB
testcase_04 AC 126 ms
84,920 KB
testcase_05 AC 125 ms
84,920 KB
testcase_06 AC 127 ms
84,920 KB
testcase_07 AC 957 ms
90,636 KB
testcase_08 AC 993 ms
90,924 KB
testcase_09 AC 972 ms
90,636 KB
testcase_10 AC 127 ms
84,920 KB
testcase_11 AC 502 ms
90,296 KB
testcase_12 AC 1,190 ms
91,272 KB
testcase_13 AC 424 ms
90,168 KB
testcase_14 AC 887 ms
90,756 KB
testcase_15 AC 1,712 ms
92,352 KB
testcase_16 AC 279 ms
90,168 KB
testcase_17 AC 188 ms
89,528 KB
testcase_18 AC 305 ms
89,912 KB
testcase_19 AC 243 ms
89,912 KB
testcase_20 AC 540 ms
90,424 KB
testcase_21 AC 312 ms
90,296 KB
testcase_22 AC 1,182 ms
91,016 KB
testcase_23 AC 225 ms
89,528 KB
testcase_24 AC 349 ms
90,168 KB
testcase_25 AC 189 ms
89,528 KB
testcase_26 AC 381 ms
90,040 KB
testcase_27 AC 642 ms
90,168 KB
testcase_28 AC 233 ms
89,528 KB
testcase_29 AC 327 ms
90,040 KB
testcase_30 AC 1,154 ms
91,164 KB
testcase_31 AC 184 ms
90,936 KB
testcase_32 AC 189 ms
90,808 KB
testcase_33 AC 141 ms
88,760 KB
testcase_34 AC 124 ms
84,920 KB
testcase_35 AC 123 ms
84,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
# O(EV)

    

g = []


n,m = map(int,input().split())
n *= 2
alist = list(map(int,input().split()))
edge = [[] for i in range(n//2)]
for i in range(m):
    a,b,c = map(int,input().split())
    edge[b-1].append(a-1)
    a -= 1
    b -= 1
    g.append((a*2+1,b*2,c))
for i in range(n//2):
    g.append((i*2,i*2+1,-alist[i]))
start = n//2-1
d = collections.deque()
dist = [10**18 for i in range(n//2)]
d.append(start)
dist[start] = 0
while d:
    now = d.popleft()
    for i in edge[now]:
        if dist[i] > dist[now] + 1:
            dist[i] = dist[now] + 1
            d.append(i)


d = [float('inf')]*n # 各頂点への最小コスト
d[0] = 0 # 自身への距離は0
for i in range(n):
    update = False # 更新が行われたか
    check = [False for rrfrf in range(n)]
    for x, y, z in g:
        if d[y] > d[x] + z:
            d[y] = d[x] + z
            update = True
            check[y] = True
    if not update:
        break
    if i == n-1:
        for j in range(n):
            if check[j] == True and dist[j//2] != 10**18:
                exit(print('inf'))

        


print(-d[-1])
0