結果

問題 No.1898 Battle and Exchange
ユーザー chineristACchineristAC
提出日時 2022-04-08 22:50:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,955 ms / 5,000 ms
コード長 2,540 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 274,320 KB
最終ジャッジ日時 2024-05-06 08:32:08
合計ジャッジ時間 67,790 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
56,832 KB
testcase_01 AC 51 ms
56,576 KB
testcase_02 AC 52 ms
56,576 KB
testcase_03 AC 50 ms
56,832 KB
testcase_04 AC 166 ms
78,928 KB
testcase_05 AC 172 ms
78,312 KB
testcase_06 AC 190 ms
79,248 KB
testcase_07 AC 185 ms
79,328 KB
testcase_08 AC 135 ms
78,464 KB
testcase_09 AC 508 ms
89,932 KB
testcase_10 AC 54 ms
62,080 KB
testcase_11 AC 76 ms
72,448 KB
testcase_12 AC 194 ms
79,156 KB
testcase_13 AC 49 ms
56,576 KB
testcase_14 AC 179 ms
79,280 KB
testcase_15 AC 53 ms
62,336 KB
testcase_16 AC 163 ms
78,664 KB
testcase_17 AC 360 ms
93,036 KB
testcase_18 AC 875 ms
150,024 KB
testcase_19 AC 1,403 ms
217,000 KB
testcase_20 AC 1,448 ms
224,576 KB
testcase_21 AC 4,053 ms
272,612 KB
testcase_22 AC 100 ms
77,312 KB
testcase_23 AC 151 ms
78,352 KB
testcase_24 AC 146 ms
78,592 KB
testcase_25 AC 180 ms
79,344 KB
testcase_26 AC 59 ms
63,872 KB
testcase_27 AC 212 ms
79,412 KB
testcase_28 AC 173 ms
78,776 KB
testcase_29 AC 346 ms
82,304 KB
testcase_30 AC 96 ms
77,696 KB
testcase_31 AC 66 ms
66,816 KB
testcase_32 AC 882 ms
210,944 KB
testcase_33 AC 1,432 ms
270,372 KB
testcase_34 AC 644 ms
177,664 KB
testcase_35 AC 1,132 ms
253,184 KB
testcase_36 AC 875 ms
225,792 KB
testcase_37 AC 418 ms
112,896 KB
testcase_38 AC 2,395 ms
268,760 KB
testcase_39 AC 1,972 ms
270,888 KB
testcase_40 AC 2,712 ms
271,736 KB
testcase_41 AC 2,156 ms
269,656 KB
testcase_42 AC 290 ms
85,912 KB
testcase_43 AC 2,810 ms
263,028 KB
testcase_44 AC 80 ms
75,264 KB
testcase_45 AC 394 ms
99,028 KB
testcase_46 AC 1,225 ms
205,832 KB
testcase_47 AC 249 ms
86,436 KB
testcase_48 AC 454 ms
107,776 KB
testcase_49 AC 231 ms
79,712 KB
testcase_50 AC 213 ms
80,240 KB
testcase_51 AC 277 ms
80,548 KB
testcase_52 AC 340 ms
81,548 KB
testcase_53 AC 901 ms
103,488 KB
testcase_54 AC 997 ms
105,392 KB
testcase_55 AC 866 ms
109,308 KB
testcase_56 AC 1,282 ms
123,264 KB
testcase_57 AC 3,868 ms
264,908 KB
testcase_58 AC 4,461 ms
272,456 KB
testcase_59 AC 4,955 ms
270,224 KB
testcase_60 AC 4,740 ms
274,320 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]))

mask = 2**20-1

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]:
                    S = sum(card[nv])
                    heappush(strong,(S<<20)+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:
            V = strong[0]
            val,nv = V>>20,V&mask
            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]:
                        S = sum(card[nnv])
                        heappush(strong,(S<<20)+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