結果

問題 No.1898 Battle and Exchange
ユーザー chineristACchineristAC
提出日時 2022-04-08 22:46:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,032 ms / 5,000 ms
コード長 2,431 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 276,288 KB
最終ジャッジ日時 2023-08-19 01:18:03
合計ジャッジ時間 61,987 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
74,688 KB
testcase_01 AC 91 ms
74,668 KB
testcase_02 AC 93 ms
74,444 KB
testcase_03 AC 90 ms
74,568 KB
testcase_04 AC 191 ms
83,088 KB
testcase_05 AC 194 ms
83,136 KB
testcase_06 AC 221 ms
84,040 KB
testcase_07 AC 215 ms
83,728 KB
testcase_08 AC 166 ms
82,500 KB
testcase_09 AC 589 ms
100,576 KB
testcase_10 AC 95 ms
78,024 KB
testcase_11 AC 122 ms
81,332 KB
testcase_12 AC 232 ms
83,844 KB
testcase_13 AC 90 ms
74,376 KB
testcase_14 AC 223 ms
84,156 KB
testcase_15 AC 94 ms
78,448 KB
testcase_16 AC 191 ms
82,932 KB
testcase_17 AC 349 ms
98,588 KB
testcase_18 AC 739 ms
159,540 KB
testcase_19 AC 1,163 ms
219,688 KB
testcase_20 AC 1,144 ms
228,892 KB
testcase_21 AC 3,162 ms
274,696 KB
testcase_22 AC 134 ms
81,432 KB
testcase_23 AC 187 ms
82,400 KB
testcase_24 AC 180 ms
83,592 KB
testcase_25 AC 217 ms
84,356 KB
testcase_26 AC 97 ms
78,436 KB
testcase_27 AC 262 ms
84,476 KB
testcase_28 AC 225 ms
83,672 KB
testcase_29 AC 416 ms
92,924 KB
testcase_30 AC 122 ms
81,572 KB
testcase_31 AC 103 ms
78,468 KB
testcase_32 AC 767 ms
209,868 KB
testcase_33 AC 1,149 ms
268,908 KB
testcase_34 AC 558 ms
176,788 KB
testcase_35 AC 954 ms
258,720 KB
testcase_36 AC 748 ms
230,512 KB
testcase_37 AC 394 ms
116,020 KB
testcase_38 AC 1,893 ms
271,452 KB
testcase_39 AC 1,601 ms
270,360 KB
testcase_40 AC 2,140 ms
270,192 KB
testcase_41 AC 1,665 ms
265,036 KB
testcase_42 AC 292 ms
91,324 KB
testcase_43 AC 2,461 ms
268,804 KB
testcase_44 AC 116 ms
81,592 KB
testcase_45 AC 377 ms
106,204 KB
testcase_46 AC 1,069 ms
218,180 KB
testcase_47 AC 274 ms
92,416 KB
testcase_48 AC 455 ms
112,944 KB
testcase_49 AC 266 ms
85,384 KB
testcase_50 AC 242 ms
83,996 KB
testcase_51 AC 299 ms
84,704 KB
testcase_52 AC 406 ms
89,640 KB
testcase_53 AC 1,074 ms
127,676 KB
testcase_54 AC 1,264 ms
137,480 KB
testcase_55 AC 982 ms
127,976 KB
testcase_56 AC 1,536 ms
157,780 KB
testcase_57 AC 3,245 ms
268,080 KB
testcase_58 AC 3,727 ms
274,724 KB
testcase_59 AC 4,032 ms
276,288 KB
testcase_60 AC 3,907 ms
272,628 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 = 10**9
ng = 2
while ok-ng>1:
    mid = (ok+ng)//2
    if cond(mid):
        ok = mid
    else:
        ng = mid

print(1,1,ok-2)




    
    

0