結果

問題 No.1898 Battle and Exchange
ユーザー polylogKpolylogK
提出日時 2021-12-25 20:06:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,806 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 12,112 KB
実行使用メモリ 54,276 KB
最終ジャッジ日時 2023-10-22 05:48:53
合計ジャッジ時間 29,285 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,296 KB
testcase_01 AC 31 ms
10,296 KB
testcase_02 AC 31 ms
10,296 KB
testcase_03 AC 31 ms
10,296 KB
testcase_04 AC 32 ms
10,340 KB
testcase_05 AC 33 ms
10,332 KB
testcase_06 AC 35 ms
10,404 KB
testcase_07 AC 34 ms
10,388 KB
testcase_08 WA -
testcase_09 AC 102 ms
12,604 KB
testcase_10 WA -
testcase_11 AC 31 ms
10,304 KB
testcase_12 AC 42 ms
10,440 KB
testcase_13 AC 30 ms
10,296 KB
testcase_14 AC 38 ms
10,400 KB
testcase_15 AC 31 ms
10,296 KB
testcase_16 AC 34 ms
10,336 KB
testcase_17 AC 72 ms
12,428 KB
testcase_18 AC 219 ms
19,152 KB
testcase_19 AC 329 ms
23,588 KB
testcase_20 AC 327 ms
24,820 KB
testcase_21 AC 935 ms
46,600 KB
testcase_22 AC 32 ms
10,304 KB
testcase_23 AC 34 ms
10,336 KB
testcase_24 AC 34 ms
10,336 KB
testcase_25 AC 36 ms
10,376 KB
testcase_26 AC 31 ms
10,300 KB
testcase_27 AC 58 ms
10,664 KB
testcase_28 AC 67 ms
10,788 KB
testcase_29 AC 139 ms
11,408 KB
testcase_30 AC 40 ms
10,400 KB
testcase_31 AC 33 ms
10,312 KB
testcase_32 AC 332 ms
23,252 KB
testcase_33 AC 603 ms
33,228 KB
testcase_34 AC 279 ms
20,888 KB
testcase_35 AC 448 ms
27,696 KB
testcase_36 AC 394 ms
25,640 KB
testcase_37 AC 135 ms
15,380 KB
testcase_38 AC 1,302 ms
54,276 KB
testcase_39 AC 768 ms
44,860 KB
testcase_40 AC 1,180 ms
49,152 KB
testcase_41 AC 683 ms
42,212 KB
testcase_42 AC 66 ms
11,896 KB
testcase_43 AC 590 ms
37,160 KB
testcase_44 AC 31 ms
10,316 KB
testcase_45 AC 106 ms
13,456 KB
testcase_46 AC 356 ms
23,540 KB
testcase_47 AC 82 ms
12,452 KB
testcase_48 AC 132 ms
15,076 KB
testcase_49 AC 55 ms
10,812 KB
testcase_50 AC 54 ms
10,728 KB
testcase_51 AC 55 ms
10,752 KB
testcase_52 AC 80 ms
10,844 KB
testcase_53 AC 259 ms
17,616 KB
testcase_54 AC 345 ms
17,620 KB
testcase_55 AC 338 ms
19,164 KB
testcase_56 AC 378 ms
20,724 KB
testcase_57 AC 1,187 ms
50,268 KB
testcase_58 AC 1,101 ms
50,272 KB
testcase_59 AC 1,035 ms
50,276 KB
testcase_60 AC 1,087 ms
50,272 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