結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
86,740 KB
testcase_01 AC 116 ms
86,528 KB
testcase_02 AC 133 ms
89,800 KB
testcase_03 AC 106 ms
86,912 KB
testcase_04 AC 116 ms
86,804 KB
testcase_05 AC 108 ms
86,604 KB
testcase_06 AC 116 ms
86,912 KB
testcase_07 AC 111 ms
86,812 KB
testcase_08 AC 134 ms
89,572 KB
testcase_09 AC 116 ms
87,072 KB
testcase_10 AC 131 ms
89,984 KB
testcase_11 AC 130 ms
88,960 KB
testcase_12 AC 132 ms
89,216 KB
testcase_13 AC 131 ms
89,088 KB
testcase_14 AC 132 ms
89,216 KB
testcase_15 AC 186 ms
92,032 KB
testcase_16 AC 1,298 ms
101,888 KB
testcase_17 AC 401 ms
92,160 KB
testcase_18 AC 341 ms
94,924 KB
testcase_19 AC 179 ms
90,752 KB
testcase_20 AC 439 ms
101,760 KB
testcase_21 AC 331 ms
102,016 KB
testcase_22 AC 361 ms
92,128 KB
testcase_23 AC 182 ms
89,692 KB
testcase_24 AC 1,110 ms
101,780 KB
testcase_25 AC 110 ms
86,528 KB
testcase_26 AC 162 ms
102,016 KB
testcase_27 AC 107 ms
86,784 KB
testcase_28 AC 191 ms
101,760 KB
testcase_29 AC 112 ms
86,400 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