結果

問題 No.2712 Play more!
ユーザー tkykwtnbtkykwtnb
提出日時 2024-04-13 14:18:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 958 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 212,768 KB
最終ジャッジ日時 2024-04-13 14:18:59
合計ジャッジ時間 5,067 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
17,948 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 30 ms
10,880 KB
testcase_07 AC 170 ms
11,904 KB
testcase_08 AC 178 ms
11,904 KB
testcase_09 AC 173 ms
11,904 KB
testcase_10 AC 31 ms
10,880 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict,deque
N,M=map(int,input().split())
A=list(map(int,input().split()))
G=[[] for _ in range(N)]
cost=defaultdict(int)
for _ in range(M):
    a,b,c=map(int,input().split())
    a-=1;b-=1
    G[a].append(b)
    cost[(a,b)]=c
kouho=[]
loop=set()
Q=deque()
Q.append((0,[]))
while Q:
    d,r=Q.popleft()
    r.append(d)
    if d==N-1:
        kouho.append(r)
        continue
    s=set(r)
    for n in G[d]:
        if n in s:
            tmp=r[r.index(n):]+[n]
            sat=0
            for i in range(len(tmp)-1):
                sat+=A[tmp[i]]-cost[(tmp[i],tmp[i+1])]
            sat+=tmp[-1]
            if sat>0:
                loop|=set(tmp)
        else:
            Q.append((n,r[:]))
ans=0
for k in kouho:
    for i in k:
        if i in loop:
            print("inf")
            exit()
    sat=0
    for i in range(len(k)-1):
        sat+=A[k[i]]-cost[(k[i],k[i+1])]
    sat+=A[-1]
    ans=max(ans,sat)
print(ans)
0