結果

問題 No.845 最長の切符
ユーザー vwxyzvwxyz
提出日時 2024-04-07 20:28:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,393 ms / 3,000 ms
コード長 597 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 89,600 KB
最終ジャッジ日時 2024-04-07 20:29:06
合計ジャッジ時間 7,300 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 69 ms
72,788 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 41 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 57 ms
66,532 KB
testcase_09 AC 44 ms
59,708 KB
testcase_10 AC 64 ms
68,864 KB
testcase_11 AC 54 ms
66,416 KB
testcase_12 AC 63 ms
68,608 KB
testcase_13 AC 55 ms
64,320 KB
testcase_14 AC 61 ms
68,620 KB
testcase_15 AC 136 ms
79,108 KB
testcase_16 AC 1,393 ms
89,484 KB
testcase_17 AC 394 ms
79,052 KB
testcase_18 AC 283 ms
82,508 KB
testcase_19 AC 137 ms
77,440 KB
testcase_20 AC 438 ms
89,600 KB
testcase_21 AC 272 ms
89,600 KB
testcase_22 AC 361 ms
79,072 KB
testcase_23 AC 129 ms
73,216 KB
testcase_24 AC 1,215 ms
89,472 KB
testcase_25 AC 36 ms
53,460 KB
testcase_26 AC 127 ms
89,600 KB
testcase_27 AC 39 ms
53,460 KB
testcase_28 AC 132 ms
89,600 KB
testcase_29 AC 40 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
graph=[[] for x in range(N)]
for m in range(M):
    a,b,c=map(int,input().split())
    a-=1;b-=1
    graph[a].append((b,c))
    graph[b].append((a,c))
inf=1<<30
dp=[[-inf]*N for bit in range(1<<N)]
for bit in range(1,1<<N):
    for x in range(N):
        if bit==1<<x:
            dp[bit][x]=0
            break
    else:
        for y in range(N):
            if bit&1<<y:
                for x,c in graph[y]:
                    if bit&1<<x:
                        dp[bit][y]=max(dp[bit][y],dp[bit^1<<y][x]+c)
ans=max(max(dp[bit]) for bit in range(1<<N))
print(ans)
0