結果

問題 No.845 最長の切符
ユーザー tcltktcltk
提出日時 2021-05-19 17:13:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,417 ms / 3,000 ms
コード長 1,197 bytes
コンパイル時間 942 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 102,120 KB
最終ジャッジ日時 2024-04-18 03:23:45
合計ジャッジ時間 9,616 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
86,784 KB
testcase_01 AC 132 ms
86,656 KB
testcase_02 AC 132 ms
87,184 KB
testcase_03 AC 127 ms
86,656 KB
testcase_04 AC 127 ms
86,760 KB
testcase_05 AC 128 ms
86,912 KB
testcase_06 AC 126 ms
86,656 KB
testcase_07 AC 127 ms
86,784 KB
testcase_08 AC 149 ms
89,600 KB
testcase_09 AC 127 ms
86,656 KB
testcase_10 AC 157 ms
89,420 KB
testcase_11 AC 146 ms
88,832 KB
testcase_12 AC 150 ms
89,600 KB
testcase_13 AC 147 ms
89,088 KB
testcase_14 AC 146 ms
89,572 KB
testcase_15 AC 215 ms
91,952 KB
testcase_16 AC 1,417 ms
102,120 KB
testcase_17 AC 442 ms
91,872 KB
testcase_18 AC 369 ms
95,232 KB
testcase_19 AC 207 ms
90,272 KB
testcase_20 AC 493 ms
102,016 KB
testcase_21 AC 359 ms
102,048 KB
testcase_22 AC 410 ms
91,776 KB
testcase_23 AC 208 ms
89,600 KB
testcase_24 AC 1,200 ms
102,112 KB
testcase_25 AC 129 ms
86,788 KB
testcase_26 AC 169 ms
101,888 KB
testcase_27 AC 125 ms
86,456 KB
testcase_28 AC 171 ms
102,008 KB
testcase_29 AC 128 ms
87,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """5 5
# 3 4 36519
# 3 4 96660
# 2 1 36308
# 3 5 55396
# 4 1 20274
# """
# sys.stdin = io.StringIO(_INPUT)


def main():
    N, M = map(int, input().split())
    G = [list() for _ in range(N)]
    for i in range(M):
        a, b, c = map(int, input().split())
        G[a-1].append((b-1, c))
        G[b-1].append((a-1, c))

    dp = [[10**10] * N for _ in range(1<<N)]
    ans = 0
    for i in range(N):
        dp[1<<i][i] = 0
    for s in range(1<<N):
        for i in range(N):
            if dp[s][i] == 10**10 or not(s & (1<<i)):
                continue
            for j, cost in G[i]:
                if s & (1<<j):
                    continue
                s1 = s | (1<<j)
                v = dp[s][i] + cost
                if dp[s1][j] == 10**10 or dp[s1][j] < v:
                    dp[s1][j] = v
                    ans = max(ans, dp[s1][j])

    print(ans)

if __name__ == '__main__':
    main()
0