結果

問題 No.1898 Battle and Exchange
ユーザー polylogKpolylogK
提出日時 2021-12-25 20:06:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,806 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 81,976 KB
実行使用メモリ 105,876 KB
最終ジャッジ日時 2024-09-22 05:58:16
合計ジャッジ時間 21,890 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,556 KB
testcase_01 AC 38 ms
53,856 KB
testcase_02 AC 39 ms
53,900 KB
testcase_03 AC 38 ms
53,936 KB
testcase_04 AC 46 ms
57,060 KB
testcase_05 AC 49 ms
56,500 KB
testcase_06 AC 61 ms
66,560 KB
testcase_07 AC 57 ms
63,924 KB
testcase_08 WA -
testcase_09 AC 141 ms
78,996 KB
testcase_10 WA -
testcase_11 AC 42 ms
54,816 KB
testcase_12 AC 69 ms
71,284 KB
testcase_13 AC 39 ms
53,796 KB
testcase_14 AC 65 ms
70,868 KB
testcase_15 AC 37 ms
53,544 KB
testcase_16 AC 56 ms
64,572 KB
testcase_17 AC 158 ms
79,252 KB
testcase_18 AC 212 ms
83,092 KB
testcase_19 AC 244 ms
85,200 KB
testcase_20 AC 232 ms
86,004 KB
testcase_21 AC 418 ms
98,080 KB
testcase_22 AC 40 ms
54,228 KB
testcase_23 AC 53 ms
62,880 KB
testcase_24 AC 53 ms
62,788 KB
testcase_25 AC 77 ms
75,044 KB
testcase_26 AC 40 ms
54,444 KB
testcase_27 AC 77 ms
76,420 KB
testcase_28 AC 80 ms
76,572 KB
testcase_29 AC 94 ms
76,448 KB
testcase_30 AC 68 ms
71,480 KB
testcase_31 AC 46 ms
56,112 KB
testcase_32 AC 197 ms
84,364 KB
testcase_33 AC 266 ms
90,356 KB
testcase_34 AC 183 ms
83,140 KB
testcase_35 AC 226 ms
87,048 KB
testcase_36 AC 214 ms
85,544 KB
testcase_37 AC 189 ms
81,176 KB
testcase_38 AC 602 ms
105,876 KB
testcase_39 AC 383 ms
100,120 KB
testcase_40 AC 546 ms
102,332 KB
testcase_41 AC 362 ms
97,728 KB
testcase_42 AC 166 ms
79,184 KB
testcase_43 AC 300 ms
93,684 KB
testcase_44 AC 42 ms
54,444 KB
testcase_45 AC 174 ms
79,688 KB
testcase_46 AC 255 ms
85,212 KB
testcase_47 AC 165 ms
79,092 KB
testcase_48 AC 168 ms
79,952 KB
testcase_49 AC 89 ms
76,612 KB
testcase_50 AC 83 ms
76,712 KB
testcase_51 AC 83 ms
76,620 KB
testcase_52 AC 84 ms
76,280 KB
testcase_53 AC 189 ms
80,904 KB
testcase_54 AC 191 ms
82,064 KB
testcase_55 AC 218 ms
82,056 KB
testcase_56 AC 215 ms
82,904 KB
testcase_57 AC 536 ms
100,080 KB
testcase_58 AC 481 ms
99,948 KB
testcase_59 AC 452 ms
100,352 KB
testcase_60 AC 478 ms
100,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq


def solve(n, m, graph, abc):
    for i in range(n):
        abc[i].sort(reverse=True)

    ans = sum(abc[0]) - 1
    myabc = [ans, 1, 1]
    myabc[1] = abc[0][0]

    v = graph[0][0]
    for to in graph[0]:
        if sum(abc[to]) < sum(abc[v]):
            v = to

    if sum(abc[v]) >= sum(myabc):
        ans += sum(abc[to]) - sum(myabc) + 1

    myabc = [ans, 1, 1]

    q, visit = [], [False] * n
    heapq.heappush(q, (sum(abc[0]), 0))
    visit[0] = True

    def update(myabc, x):
        myabc.append(x)
        myabc.sort(reverse=True)
        return myabc[:3]

    while q:
        nowsum, now = heapq.heappop(q)

        if nowsum >= sum(myabc):
            diff = nowsum - sum(myabc) + 1
            if myabc[0] == ans:
                ans += diff
                myabc[0] += diff
            elif myabc[1] == ans:
                ans += diff
                myabc[1] += diff
            elif myabc[2] == ans:
                ans += diff
                myabc[2] += diff
            else:
                ans = myabc[2] + diff
                myabc[2] += diff

        if now == n - 1:
            return ans, 1, 1

        myabc = update(myabc, abc[now][0])
        myabc = update(myabc, abc[now][1])
        myabc = update(myabc, abc[now][2])

        for to in graph[now]:
            if visit[to]:
                continue

            heapq.heappush(q, (sum(abc[to]), to))
            visit[to] = True


if __name__ == '__main__':
    n, m = map(int, input().split())
    graph = [[] for _ in range(n)]

    for _ in range(m):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        graph[u].append(v)
        graph[v].append(u)

    abc = [list(map(int, input().split())) for _ in range(n)]

    a, b, c = solve(n, m, graph, abc)
    print(a, b, c)
0