結果

問題 No.1898 Battle and Exchange
ユーザー 👑 rin204rin204
提出日時 2022-04-08 23:06:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,604 ms / 5,000 ms
コード長 1,335 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 183,028 KB
最終ジャッジ日時 2023-08-19 01:42:00
合計ジャッジ時間 40,210 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
71,088 KB
testcase_01 AC 64 ms
71,340 KB
testcase_02 AC 65 ms
71,452 KB
testcase_03 AC 65 ms
71,128 KB
testcase_04 AC 109 ms
77,620 KB
testcase_05 AC 103 ms
77,468 KB
testcase_06 AC 132 ms
77,896 KB
testcase_07 AC 116 ms
77,932 KB
testcase_08 AC 95 ms
77,344 KB
testcase_09 AC 214 ms
81,728 KB
testcase_10 AC 67 ms
71,368 KB
testcase_11 AC 76 ms
76,532 KB
testcase_12 AC 109 ms
78,044 KB
testcase_13 AC 67 ms
71,356 KB
testcase_14 AC 107 ms
77,900 KB
testcase_15 AC 67 ms
71,468 KB
testcase_16 AC 98 ms
77,508 KB
testcase_17 AC 219 ms
80,080 KB
testcase_18 AC 453 ms
86,352 KB
testcase_19 AC 611 ms
88,696 KB
testcase_20 AC 648 ms
88,720 KB
testcase_21 AC 1,174 ms
100,296 KB
testcase_22 AC 73 ms
76,404 KB
testcase_23 AC 97 ms
77,532 KB
testcase_24 AC 93 ms
77,432 KB
testcase_25 AC 119 ms
78,208 KB
testcase_26 AC 71 ms
75,824 KB
testcase_27 AC 120 ms
77,684 KB
testcase_28 AC 121 ms
78,420 KB
testcase_29 AC 143 ms
78,560 KB
testcase_30 AC 111 ms
77,868 KB
testcase_31 AC 80 ms
76,348 KB
testcase_32 AC 279 ms
85,392 KB
testcase_33 AC 447 ms
94,184 KB
testcase_34 AC 249 ms
84,320 KB
testcase_35 AC 330 ms
88,340 KB
testcase_36 AC 321 ms
87,404 KB
testcase_37 AC 283 ms
83,152 KB
testcase_38 AC 2,604 ms
183,028 KB
testcase_39 AC 1,555 ms
144,060 KB
testcase_40 AC 1,792 ms
151,368 KB
testcase_41 AC 1,400 ms
135,916 KB
testcase_42 AC 204 ms
79,852 KB
testcase_43 AC 1,229 ms
103,112 KB
testcase_44 AC 75 ms
76,544 KB
testcase_45 AC 266 ms
81,212 KB
testcase_46 AC 547 ms
87,928 KB
testcase_47 AC 222 ms
80,072 KB
testcase_48 AC 274 ms
83,952 KB
testcase_49 AC 136 ms
78,656 KB
testcase_50 AC 130 ms
78,544 KB
testcase_51 AC 139 ms
78,616 KB
testcase_52 AC 132 ms
78,692 KB
testcase_53 AC 277 ms
83,776 KB
testcase_54 AC 238 ms
82,880 KB
testcase_55 AC 338 ms
84,564 KB
testcase_56 AC 316 ms
85,220 KB
testcase_57 AC 1,890 ms
107,792 KB
testcase_58 AC 1,731 ms
106,000 KB
testcase_59 AC 2,026 ms
108,652 KB
testcase_60 AC 1,619 ms
105,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
最初に持つ数は
1 1 x
でいい

交換も一番小さいのと大きいのでいい

にぶたん
"""
from heapq import*

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    edges[u].append(v)
    edges[v].append(u)
    
tot = [0] * n
A = [0] * n
B = [0] * n
C = [0] * n
for i in range(n):
    A[i], B[i], C[i] = map(int, input().split())
    tot[i] = A[i] + B[i] + C[i]
    
def ok(x):
    if x  + 2 <= A[0] + B[0] + C[0]:
        return False
    t = x + max(A[0], B[0], C[0]) + 1
    ok = False
    for npos in edges[0]:
        if t > A[npos] + B[npos] + C[npos]:
            ok = True
            break
    if not ok:
        return False
    
    hq = [(tot[0], 0)]
    used = [False] * n
    used[0] = True
    a, b, c = x, 1, 1
    while hq:
        t, pos = heappop(hq)
        if t >= a + b + c:
            return False
        for npos in edges[pos]:
            if not used[npos]:
                used[npos] = True
                heappush(hq, (tot[npos], npos))
        lst = [a, b, c, A[pos], B[pos], C[pos]]
        lst.sort()
        a, b, c = lst[3:]

    return True
    
l = 1
r = 3 * 10 ** 8
while r - l > 1:
    mid = (l + r) // 2
    if ok(mid):
        r = mid
    else:
        l = mid
print(1, 1, r)
    
0