結果

問題 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
コンパイル時間 84 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 54,912 KB
最終ジャッジ日時 2024-09-22 07:08:15
合計ジャッジ時間 29,226 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,008 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 31 ms
11,136 KB
testcase_03 AC 31 ms
11,008 KB
testcase_04 AC 33 ms
11,008 KB
testcase_05 AC 34 ms
11,008 KB
testcase_06 AC 35 ms
11,008 KB
testcase_07 AC 35 ms
11,136 KB
testcase_08 WA -
testcase_09 AC 115 ms
13,440 KB
testcase_10 WA -
testcase_11 AC 31 ms
11,136 KB
testcase_12 AC 43 ms
11,136 KB
testcase_13 AC 31 ms
11,136 KB
testcase_14 AC 40 ms
11,008 KB
testcase_15 AC 31 ms
11,136 KB
testcase_16 AC 34 ms
11,008 KB
testcase_17 AC 80 ms
13,056 KB
testcase_18 AC 242 ms
19,968 KB
testcase_19 AC 368 ms
24,448 KB
testcase_20 AC 365 ms
25,728 KB
testcase_21 AC 999 ms
47,232 KB
testcase_22 AC 31 ms
11,136 KB
testcase_23 AC 34 ms
11,008 KB
testcase_24 AC 34 ms
11,136 KB
testcase_25 AC 37 ms
11,008 KB
testcase_26 AC 32 ms
11,136 KB
testcase_27 AC 62 ms
11,392 KB
testcase_28 AC 72 ms
11,520 KB
testcase_29 AC 153 ms
12,160 KB
testcase_30 AC 40 ms
11,136 KB
testcase_31 AC 32 ms
11,136 KB
testcase_32 AC 369 ms
24,192 KB
testcase_33 AC 645 ms
33,920 KB
testcase_34 AC 316 ms
22,016 KB
testcase_35 AC 504 ms
28,544 KB
testcase_36 AC 432 ms
26,496 KB
testcase_37 AC 141 ms
16,000 KB
testcase_38 AC 1,364 ms
54,912 KB
testcase_39 AC 827 ms
45,696 KB
testcase_40 AC 1,190 ms
50,048 KB
testcase_41 AC 737 ms
43,008 KB
testcase_42 AC 72 ms
12,544 KB
testcase_43 AC 646 ms
38,144 KB
testcase_44 AC 32 ms
11,136 KB
testcase_45 AC 115 ms
14,208 KB
testcase_46 AC 392 ms
24,320 KB
testcase_47 AC 89 ms
13,056 KB
testcase_48 AC 145 ms
15,744 KB
testcase_49 AC 61 ms
11,520 KB
testcase_50 AC 59 ms
11,520 KB
testcase_51 AC 59 ms
11,392 KB
testcase_52 AC 85 ms
11,648 KB
testcase_53 AC 287 ms
18,432 KB
testcase_54 AC 379 ms
18,560 KB
testcase_55 AC 364 ms
19,840 KB
testcase_56 AC 420 ms
21,632 KB
testcase_57 AC 1,261 ms
51,072 KB
testcase_58 AC 1,177 ms
51,072 KB
testcase_59 AC 1,106 ms
51,072 KB
testcase_60 AC 1,162 ms
51,072 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