結果

問題 No.1898 Battle and Exchange
ユーザー chineristACchineristAC
提出日時 2022-04-08 22:52:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,417 ms / 5,000 ms
コード長 2,436 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 273,088 KB
最終ジャッジ日時 2024-05-06 08:35:33
合計ジャッジ時間 66,504 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
56,832 KB
testcase_01 AC 48 ms
56,576 KB
testcase_02 AC 47 ms
57,088 KB
testcase_03 AC 47 ms
56,448 KB
testcase_04 AC 167 ms
79,020 KB
testcase_05 AC 156 ms
78,080 KB
testcase_06 AC 186 ms
79,280 KB
testcase_07 AC 187 ms
79,404 KB
testcase_08 AC 133 ms
78,080 KB
testcase_09 AC 667 ms
97,140 KB
testcase_10 AC 51 ms
62,336 KB
testcase_11 AC 93 ms
77,440 KB
testcase_12 AC 200 ms
79,636 KB
testcase_13 AC 49 ms
56,192 KB
testcase_14 AC 174 ms
78,780 KB
testcase_15 AC 53 ms
62,080 KB
testcase_16 AC 155 ms
78,320 KB
testcase_17 AC 320 ms
90,444 KB
testcase_18 AC 947 ms
154,492 KB
testcase_19 AC 1,405 ms
203,172 KB
testcase_20 AC 1,389 ms
216,396 KB
testcase_21 AC 3,023 ms
264,704 KB
testcase_22 AC 92 ms
77,688 KB
testcase_23 AC 141 ms
78,252 KB
testcase_24 AC 133 ms
78,208 KB
testcase_25 AC 170 ms
78,716 KB
testcase_26 AC 54 ms
63,744 KB
testcase_27 AC 241 ms
79,648 KB
testcase_28 AC 195 ms
79,372 KB
testcase_29 AC 603 ms
94,720 KB
testcase_30 AC 95 ms
78,000 KB
testcase_31 AC 58 ms
66,560 KB
testcase_32 AC 762 ms
189,184 KB
testcase_33 AC 1,443 ms
268,252 KB
testcase_34 AC 584 ms
159,744 KB
testcase_35 AC 926 ms
229,376 KB
testcase_36 AC 902 ms
221,696 KB
testcase_37 AC 386 ms
100,064 KB
testcase_38 AC 2,793 ms
273,088 KB
testcase_39 AC 2,109 ms
266,780 KB
testcase_40 AC 2,350 ms
267,884 KB
testcase_41 AC 1,815 ms
266,812 KB
testcase_42 AC 271 ms
87,252 KB
testcase_43 AC 2,737 ms
264,328 KB
testcase_44 AC 74 ms
73,856 KB
testcase_45 AC 404 ms
100,652 KB
testcase_46 AC 1,028 ms
195,816 KB
testcase_47 AC 245 ms
84,752 KB
testcase_48 AC 468 ms
101,704 KB
testcase_49 AC 233 ms
79,616 KB
testcase_50 AC 196 ms
79,696 KB
testcase_51 AC 266 ms
80,300 KB
testcase_52 AC 380 ms
84,736 KB
testcase_53 AC 1,343 ms
125,576 KB
testcase_54 AC 1,657 ms
138,568 KB
testcase_55 AC 1,457 ms
138,748 KB
testcase_56 AC 1,810 ms
150,844 KB
testcase_57 AC 4,225 ms
272,088 KB
testcase_58 AC 4,146 ms
272,740 KB
testcase_59 AC 4,417 ms
267,888 KB
testcase_60 AC 3,649 ms
272,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N,M = mi()
edge = [[] for v in range(N)]
for _ in range(M):
    u,v = mi()
    edge[u-1].append(v-1)
    edge[v-1].append(u-1)

_card = []
for i in range(N):
    a,b,c = mi()
    _card.append(sorted([a,b,c]))


def cond(k):
    card = [[a for a in _card[v]] for v in range(N)]
    my_card = [1,1,k-2]
    if sum(card[0]) >= k:
        return False
    
    if my_card[0] < card[0][2]:
        my_card[0],card[0][2] = card[0][2],my_card[0]
        card[0].sort()
        my_card.sort()
    
    pq = [(-card[0][2],0)]
    visit = [False] * N
    visit[0] = True
    f = False
    for v in edge[0]:
        if sum(card[v]) < sum(my_card):
            f = True
            heappush(pq,(-card[v][2],v))
            visit[v] = True
    
    if not f:
        return False
    
    strong = []
    for v in range(N):
        if visit[v]:
            for nv in edge[v]:
                if not visit[nv]:
                    heappush(strong,(sum(card[nv]),nv))

    

    while True:
        #print(visit)
        #print(card)
        #print(my_card)
        #print(pq)
        change = False
        new_v = False

        val,v = heappop(pq)
        val = -val

        #print(val,v)

        i = card[v].index(val)

        if val > my_card[0]:
            change = True
            my_card[0],card[v][i] = card[v][i],my_card[0]
            card[v].sort()
            my_card.sort()
            heappush(pq,(-card[v][2],v))

        while strong:
            val,nv = strong[0]
            if visit[nv]:
                heappop(strong)
                continue
            if val < sum(my_card):
                new_v = True
                heappop(strong)
                visit[nv] = True
                heappush(pq,(-card[nv][2],nv))
                for nnv in edge[nv]:
                    if not visit[nnv]:
                        heappush(strong,(sum(card[nnv]),nnv))
            else:
                break
        
        if not change and not new_v:
            break
    
    return visit[-1]




ok = 3*10**8+1
ng = 2
while ok-ng>1:
    mid = (ok+ng)//2
    if cond(mid):
        ok = mid
    else:
        ng = mid

print(1,1,ok-2)




    
    

0