結果

問題 No.1898 Battle and Exchange
ユーザー tamatotamato
提出日時 2022-04-08 23:16:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,498 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 192,456 KB
最終ジャッジ日時 2023-08-19 01:52:14
合計ジャッジ時間 33,826 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,476 KB
testcase_01 AC 63 ms
71,308 KB
testcase_02 AC 64 ms
71,292 KB
testcase_03 WA -
testcase_04 AC 77 ms
76,052 KB
testcase_05 AC 78 ms
76,472 KB
testcase_06 AC 115 ms
78,216 KB
testcase_07 WA -
testcase_08 AC 94 ms
77,688 KB
testcase_09 AC 144 ms
79,644 KB
testcase_10 WA -
testcase_11 AC 78 ms
76,668 KB
testcase_12 AC 78 ms
76,828 KB
testcase_13 AC 65 ms
71,576 KB
testcase_14 AC 81 ms
76,916 KB
testcase_15 AC 64 ms
71,364 KB
testcase_16 AC 92 ms
77,672 KB
testcase_17 AC 166 ms
80,000 KB
testcase_18 AC 279 ms
86,384 KB
testcase_19 AC 433 ms
90,488 KB
testcase_20 AC 291 ms
91,480 KB
testcase_21 AC 787 ms
106,288 KB
testcase_22 AC 76 ms
76,624 KB
testcase_23 AC 75 ms
76,220 KB
testcase_24 AC 83 ms
77,164 KB
testcase_25 AC 102 ms
78,124 KB
testcase_26 AC 65 ms
71,296 KB
testcase_27 AC 105 ms
78,228 KB
testcase_28 AC 109 ms
78,268 KB
testcase_29 AC 118 ms
78,972 KB
testcase_30 AC 101 ms
78,044 KB
testcase_31 AC 72 ms
76,200 KB
testcase_32 AC 286 ms
88,820 KB
testcase_33 AC 501 ms
98,356 KB
testcase_34 AC 235 ms
87,064 KB
testcase_35 AC 334 ms
91,844 KB
testcase_36 WA -
testcase_37 AC 222 ms
85,340 KB
testcase_38 AC 2,923 ms
192,456 KB
testcase_39 AC 560 ms
144,464 KB
testcase_40 AC 2,021 ms
158,796 KB
testcase_41 AC 451 ms
137,504 KB
testcase_42 AC 163 ms
79,284 KB
testcase_43 AC 420 ms
105,764 KB
testcase_44 AC 73 ms
75,864 KB
testcase_45 AC 213 ms
81,052 KB
testcase_46 AC 520 ms
90,108 KB
testcase_47 AC 177 ms
79,852 KB
testcase_48 AC 164 ms
82,244 KB
testcase_49 AC 122 ms
79,108 KB
testcase_50 AC 121 ms
79,052 KB
testcase_51 AC 130 ms
78,704 KB
testcase_52 AC 113 ms
78,588 KB
testcase_53 AC 169 ms
81,716 KB
testcase_54 AC 207 ms
81,792 KB
testcase_55 AC 284 ms
85,360 KB
testcase_56 AC 194 ms
84,104 KB
testcase_57 WA -
testcase_58 AC 1,430 ms
112,532 KB
testcase_59 AC 1,357 ms
114,476 KB
testcase_60 AC 1,350 ms
111,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    from heapq import heappop, heappush
    input = sys.stdin.readline

    def trade(X, Y):
        Z = sorted(X + Y, reverse=True)
        return Z[:3]

    N, M = map(int, input().split())
    adj = [[] for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        adj[a].append(b)
        adj[b].append(a)
    ABC = [[0, 0, 0]] * (N + 1)
    for v in range(1, N+1):
        ABC[v] = list(map(int, input().split()))
    ABC_sum = [sum(abc) for abc in ABC]

    ans = 3 * 10 ** 8
    ans_k = -1
    for k in range(1):
        ok = 3 * 10 ** 8
        ng = 1
        mid = (ok + ng) // 2
        while ok - ng > 1:
            X = [1] * 3
            X[k] = mid

            # 頂点1で勝てるかどうか
            if sum(X) <= sum(ABC[1]):
                ng = mid
                mid = (ok + ng) // 2
                continue
            else:
                diff_max = -10 ** 8
                diff_max_idx = -1
                for i in range(3):
                    d = ABC[1][i] - X[i]
                    if d > diff_max:
                        diff_max = d
                        diff_max_idx = i
                if X[diff_max_idx] < ABC[1][diff_max_idx]:
                    X[diff_max_idx] = ABC[1][diff_max_idx]
                S = sum(X)
                flg = 0
                for u in adj[1]:
                    if S > ABC_sum[u]:
                        flg = 1
                        break
                if not flg:
                    ng = mid
                    mid = (ok + ng) // 2
                    continue
                X = trade(X, ABC[1])

            seen = [0] * (N + 1)
            pq = [(0, 1)]
            seen[1] = 1
            flg = 1
            while pq:
                s, v = heappop(pq)
                if s >= sum(X):
                    flg = 0
                    break
                else:
                    if v == N:
                        break
                    X = trade(X, ABC[v])
                    for u in adj[v]:
                        if not seen[u]:
                            heappush(pq, (ABC_sum[u], u))
                            seen[u] = 1
            if flg:
                ok = mid
            else:
                ng = mid
            mid = (ok + ng) // 2

        if ok + 2 < ans:
            ans = ok + 2
            ans_k = k
    ANS = [1] * 3
    ANS[ans_k] = ans - 2
    print(*ANS)


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