結果

問題 No.1898 Battle and Exchange
ユーザー chineristACchineristAC
提出日時 2022-04-08 22:46:39
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,431 bytes
コンパイル時間 327 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 273,580 KB
最終ジャッジ日時 2024-05-06 08:27:34
合計ジャッジ時間 74,119 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
56,704 KB
testcase_01 AC 51 ms
56,576 KB
testcase_02 AC 51 ms
56,576 KB
testcase_03 AC 49 ms
56,576 KB
testcase_04 AC 165 ms
78,812 KB
testcase_05 AC 169 ms
78,668 KB
testcase_06 AC 203 ms
79,464 KB
testcase_07 AC 194 ms
79,260 KB
testcase_08 AC 140 ms
78,336 KB
testcase_09 AC 622 ms
95,544 KB
testcase_10 AC 54 ms
62,464 KB
testcase_11 AC 88 ms
74,624 KB
testcase_12 AC 213 ms
79,496 KB
testcase_13 AC 48 ms
56,576 KB
testcase_14 AC 200 ms
79,696 KB
testcase_15 AC 58 ms
62,208 KB
testcase_16 AC 165 ms
78,692 KB
testcase_17 AC 389 ms
92,772 KB
testcase_18 AC 939 ms
151,636 KB
testcase_19 AC 1,495 ms
210,592 KB
testcase_20 AC 1,615 ms
226,764 KB
testcase_21 AC 4,232 ms
271,984 KB
testcase_22 AC 106 ms
77,440 KB
testcase_23 AC 164 ms
78,464 KB
testcase_24 AC 157 ms
78,464 KB
testcase_25 AC 196 ms
79,588 KB
testcase_26 AC 60 ms
64,000 KB
testcase_27 AC 249 ms
80,236 KB
testcase_28 AC 203 ms
79,080 KB
testcase_29 AC 442 ms
88,576 KB
testcase_30 AC 96 ms
77,696 KB
testcase_31 AC 66 ms
66,688 KB
testcase_32 AC 974 ms
210,560 KB
testcase_33 AC 1,568 ms
270,060 KB
testcase_34 AC 708 ms
174,464 KB
testcase_35 AC 1,224 ms
253,568 KB
testcase_36 AC 1,032 ms
225,792 KB
testcase_37 AC 461 ms
110,508 KB
testcase_38 AC 2,653 ms
269,136 KB
testcase_39 AC 2,259 ms
272,136 KB
testcase_40 AC 2,906 ms
270,948 KB
testcase_41 AC 2,272 ms
269,916 KB
testcase_42 AC 322 ms
85,808 KB
testcase_43 AC 3,213 ms
264,840 KB
testcase_44 AC 86 ms
75,520 KB
testcase_45 AC 400 ms
101,284 KB
testcase_46 AC 1,392 ms
213,520 KB
testcase_47 AC 278 ms
86,296 KB
testcase_48 AC 524 ms
109,568 KB
testcase_49 AC 274 ms
79,872 KB
testcase_50 AC 237 ms
79,936 KB
testcase_51 AC 298 ms
80,952 KB
testcase_52 AC 438 ms
85,504 KB
testcase_53 AC 1,273 ms
120,448 KB
testcase_54 AC 1,521 ms
131,292 KB
testcase_55 AC 1,165 ms
122,352 KB
testcase_56 AC 1,901 ms
151,552 KB
testcase_57 AC 4,130 ms
265,040 KB
testcase_58 AC 4,742 ms
271,164 KB
testcase_59 TLE -
testcase_60 TLE -
権限があれば一括ダウンロードができます

ソースコード

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