結果

問題 No.845 最長の切符
ユーザー tcltktcltk
提出日時 2021-05-19 16:58:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,098 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 102,656 KB
最終ジャッジ日時 2024-04-18 03:02:41
合計ジャッジ時間 9,672 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
86,784 KB
testcase_01 AC 124 ms
86,784 KB
testcase_02 AC 136 ms
87,360 KB
testcase_03 AC 127 ms
86,540 KB
testcase_04 AC 135 ms
86,656 KB
testcase_05 WA -
testcase_06 AC 134 ms
86,912 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 121 ms
86,912 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 121 ms
86,864 KB
testcase_26 AC 156 ms
101,888 KB
testcase_27 AC 119 ms
86,868 KB
testcase_28 AC 162 ms
101,888 KB
testcase_29 AC 126 ms
86,892 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 4
# 1 2 3
# 3 2 3
# 2 4 3
# 4 5 2
# """
# 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)
                dp[s1][j] = min(dp[s1][j], dp[s][i] + cost)
                ans = max(ans, dp[s1][j])

    print(ans)

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