結果

問題 No.845 最長の切符
ユーザー tcltktcltk
提出日時 2021-05-19 17:11:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,533 ms / 3,000 ms
コード長 1,099 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 82,316 KB
実行使用メモリ 102,016 KB
最終ジャッジ日時 2024-04-18 03:15:38
合計ジャッジ時間 11,255 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
86,644 KB
testcase_01 AC 152 ms
86,720 KB
testcase_02 AC 173 ms
89,504 KB
testcase_03 AC 149 ms
86,912 KB
testcase_04 AC 149 ms
86,528 KB
testcase_05 AC 150 ms
86,680 KB
testcase_06 AC 147 ms
86,692 KB
testcase_07 AC 148 ms
86,784 KB
testcase_08 AC 168 ms
89,216 KB
testcase_09 AC 150 ms
86,912 KB
testcase_10 AC 174 ms
89,472 KB
testcase_11 AC 171 ms
89,344 KB
testcase_12 AC 174 ms
89,372 KB
testcase_13 AC 169 ms
89,216 KB
testcase_14 AC 176 ms
89,404 KB
testcase_15 AC 236 ms
91,648 KB
testcase_16 AC 1,533 ms
101,888 KB
testcase_17 AC 495 ms
91,952 KB
testcase_18 AC 411 ms
94,848 KB
testcase_19 AC 235 ms
90,496 KB
testcase_20 AC 526 ms
101,892 KB
testcase_21 AC 396 ms
102,016 KB
testcase_22 AC 450 ms
91,648 KB
testcase_23 AC 232 ms
89,696 KB
testcase_24 AC 1,300 ms
101,888 KB
testcase_25 AC 147 ms
86,528 KB
testcase_26 AC 208 ms
101,632 KB
testcase_27 AC 150 ms
87,068 KB
testcase_28 AC 244 ms
101,888 KB
testcase_29 AC 148 ms
86,784 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 = [[0] * 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 not(s & (1<<i)):
                continue
            for j, cost in G[i]:
                if s & (1<<j):
                    continue
                s1 = s | (1<<j)
                dp[s1][j] = max(dp[s1][j], dp[s][i] + cost)
                ans = max(ans, dp[s1][j])

    print(ans)

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