結果

問題 No.1898 Battle and Exchange
ユーザー polylogKpolylogK
提出日時 2021-12-27 00:54:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 623 ms / 5,000 ms
コード長 1,652 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 105,440 KB
最終ジャッジ日時 2024-04-26 19:42:46
合計ジャッジ時間 24,421 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,480 KB
testcase_01 AC 42 ms
52,736 KB
testcase_02 AC 41 ms
52,480 KB
testcase_03 AC 41 ms
52,864 KB
testcase_04 AC 49 ms
55,552 KB
testcase_05 AC 50 ms
55,680 KB
testcase_06 AC 64 ms
64,768 KB
testcase_07 AC 63 ms
63,104 KB
testcase_08 AC 47 ms
54,528 KB
testcase_09 AC 153 ms
77,824 KB
testcase_10 AC 41 ms
52,480 KB
testcase_11 AC 43 ms
53,504 KB
testcase_12 AC 77 ms
70,400 KB
testcase_13 AC 42 ms
52,608 KB
testcase_14 AC 72 ms
69,632 KB
testcase_15 AC 42 ms
52,736 KB
testcase_16 AC 61 ms
63,104 KB
testcase_17 AC 157 ms
78,592 KB
testcase_18 AC 209 ms
82,432 KB
testcase_19 AC 239 ms
84,608 KB
testcase_20 AC 243 ms
85,632 KB
testcase_21 AC 434 ms
97,568 KB
testcase_22 AC 44 ms
53,248 KB
testcase_23 AC 58 ms
61,824 KB
testcase_24 AC 58 ms
61,824 KB
testcase_25 AC 81 ms
73,088 KB
testcase_26 AC 42 ms
52,608 KB
testcase_27 AC 88 ms
76,288 KB
testcase_28 AC 92 ms
76,032 KB
testcase_29 AC 101 ms
76,160 KB
testcase_30 AC 78 ms
70,400 KB
testcase_31 AC 50 ms
54,784 KB
testcase_32 AC 204 ms
83,968 KB
testcase_33 AC 271 ms
89,856 KB
testcase_34 AC 186 ms
82,944 KB
testcase_35 AC 229 ms
86,272 KB
testcase_36 AC 221 ms
85,376 KB
testcase_37 AC 192 ms
80,128 KB
testcase_38 AC 623 ms
105,440 KB
testcase_39 AC 391 ms
99,620 KB
testcase_40 AC 528 ms
101,744 KB
testcase_41 AC 361 ms
97,076 KB
testcase_42 AC 167 ms
78,692 KB
testcase_43 AC 310 ms
93,312 KB
testcase_44 AC 44 ms
53,632 KB
testcase_45 AC 176 ms
79,360 KB
testcase_46 AC 254 ms
84,352 KB
testcase_47 AC 168 ms
78,568 KB
testcase_48 AC 173 ms
79,232 KB
testcase_49 AC 97 ms
76,672 KB
testcase_50 AC 92 ms
76,032 KB
testcase_51 AC 91 ms
76,416 KB
testcase_52 AC 97 ms
76,288 KB
testcase_53 AC 192 ms
80,640 KB
testcase_54 AC 198 ms
81,664 KB
testcase_55 AC 225 ms
81,536 KB
testcase_56 AC 223 ms
82,560 KB
testcase_57 AC 537 ms
99,840 KB
testcase_58 AC 499 ms
99,716 KB
testcase_59 AC 435 ms
99,584 KB
testcase_60 AC 462 ms
99,840 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[v]) - sum(myabc) + 1

    myabc = [ans, 1, 1]

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

    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 += abc[now]
        myabc.sort(reverse=True)
        myabc = myabc[:3]

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

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


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