結果

問題 No.1898 Battle and Exchange
ユーザー chineristACchineristAC
提出日時 2022-04-08 22:52:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,459 ms / 5,000 ms
コード長 2,436 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 276,140 KB
最終ジャッジ日時 2023-08-19 01:26:21
合計ジャッジ時間 59,100 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
74,484 KB
testcase_01 AC 92 ms
74,624 KB
testcase_02 AC 95 ms
74,408 KB
testcase_03 AC 93 ms
74,560 KB
testcase_04 AC 196 ms
84,076 KB
testcase_05 AC 185 ms
83,484 KB
testcase_06 AC 220 ms
83,356 KB
testcase_07 AC 215 ms
84,196 KB
testcase_08 AC 169 ms
83,180 KB
testcase_09 AC 623 ms
101,908 KB
testcase_10 AC 97 ms
78,340 KB
testcase_11 AC 133 ms
81,036 KB
testcase_12 AC 224 ms
84,400 KB
testcase_13 AC 91 ms
74,560 KB
testcase_14 AC 196 ms
83,124 KB
testcase_15 AC 96 ms
78,124 KB
testcase_16 AC 179 ms
83,184 KB
testcase_17 AC 298 ms
95,968 KB
testcase_18 AC 762 ms
153,316 KB
testcase_19 AC 1,098 ms
210,264 KB
testcase_20 AC 1,082 ms
220,616 KB
testcase_21 AC 2,445 ms
267,760 KB
testcase_22 AC 158 ms
81,496 KB
testcase_23 AC 178 ms
82,924 KB
testcase_24 AC 175 ms
82,624 KB
testcase_25 AC 198 ms
82,640 KB
testcase_26 AC 98 ms
78,452 KB
testcase_27 AC 263 ms
84,596 KB
testcase_28 AC 220 ms
83,964 KB
testcase_29 AC 554 ms
99,644 KB
testcase_30 AC 132 ms
82,256 KB
testcase_31 AC 105 ms
78,768 KB
testcase_32 AC 659 ms
198,104 KB
testcase_33 AC 1,240 ms
271,188 KB
testcase_34 AC 560 ms
165,296 KB
testcase_35 AC 828 ms
235,544 KB
testcase_36 AC 798 ms
224,544 KB
testcase_37 AC 380 ms
109,084 KB
testcase_38 AC 2,238 ms
276,140 KB
testcase_39 AC 1,681 ms
270,384 KB
testcase_40 AC 1,970 ms
267,212 KB
testcase_41 AC 1,348 ms
263,892 KB
testcase_42 AC 286 ms
92,228 KB
testcase_43 AC 2,164 ms
268,808 KB
testcase_44 AC 117 ms
81,544 KB
testcase_45 AC 375 ms
106,124 KB
testcase_46 AC 893 ms
201,912 KB
testcase_47 AC 259 ms
89,840 KB
testcase_48 AC 471 ms
106,420 KB
testcase_49 AC 250 ms
84,412 KB
testcase_50 AC 219 ms
83,616 KB
testcase_51 AC 281 ms
84,836 KB
testcase_52 AC 364 ms
88,756 KB
testcase_53 AC 1,154 ms
130,656 KB
testcase_54 AC 1,407 ms
143,768 KB
testcase_55 AC 1,314 ms
144,424 KB
testcase_56 AC 1,566 ms
156,580 KB
testcase_57 AC 3,337 ms
272,420 KB
testcase_58 AC 3,353 ms
272,540 KB
testcase_59 AC 3,459 ms
266,992 KB
testcase_60 AC 2,858 ms
271,900 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