結果

問題 No.1898 Battle and Exchange
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2022-04-14 15:45:09
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,464 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 232,080 KB
最終ジャッジ日時 2023-08-25 21:13:20
合計ジャッジ時間 32,119 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 77 ms
71,552 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 246 ms
83,040 KB
testcase_10 AC 79 ms
75,104 KB
testcase_11 AC 124 ms
77,624 KB
testcase_12 AC 176 ms
79,556 KB
testcase_13 WA -
testcase_14 AC 176 ms
78,680 KB
testcase_15 AC 80 ms
75,220 KB
testcase_16 AC 154 ms
78,444 KB
testcase_17 WA -
testcase_18 AC 825 ms
93,740 KB
testcase_19 AC 1,561 ms
114,400 KB
testcase_20 WA -
testcase_21 AC 3,726 ms
202,796 KB
testcase_22 AC 120 ms
77,776 KB
testcase_23 AC 142 ms
78,480 KB
testcase_24 AC 148 ms
78,696 KB
testcase_25 AC 175 ms
79,096 KB
testcase_26 AC 87 ms
75,600 KB
testcase_27 AC 212 ms
80,628 KB
testcase_28 AC 221 ms
80,332 KB
testcase_29 AC 272 ms
84,480 KB
testcase_30 AC 192 ms
78,864 KB
testcase_31 AC 124 ms
77,788 KB
testcase_32 AC 629 ms
131,900 KB
testcase_33 AC 1,042 ms
232,080 KB
testcase_34 AC 553 ms
118,152 KB
testcase_35 AC 968 ms
156,084 KB
testcase_36 WA -
testcase_37 AC 832 ms
105,536 KB
testcase_38 TLE -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
def solv1(n,m,uv,abc):
    # 1つの辺を通ることを考える。その辺を行き来することで2頂点のカードの計6枚のうち上位3枚を手に入れられる。
    # ->通ったことのある頂点の上位3枚のカードを手札にしていると考えてよい。
    # ただし頂点1だけ別
    g=[[] for _ in range(n)]
    for u,v in uv:
        u,v=u-1,v-1
        g[u].append(v)
        g[v].append(u)
    # 頂点1に隣接する頂点の内、最弱の頂点
    nv,nvalue=-1,float('inf')
    for v in g[0]:
        value=sum(abc[v])
        if value<nvalue:
            nvalue=value
            nv=v
    # nv:1隣接頂点の内最弱頂点
    def select_card(x,y):
        i,j=0,0
        ret=[0]*4
        for i in range(3):
            if x[-1-i]<y[-1-j]:
                ret[-1-i]=y[-1-j]
                j+=1
            else:
                ret[-1-i]=x[-1-j]
                i+=1
        ret[0]=sum(ret)
        return ret
    # xは少なくとも0とnvに勝てる値ではじめる
    r=max([sum(x) for x in abc])+1
    l=nvalue+1-max(abc[0])+1
    l=max(l,sum(abc[0])+1)
    def search(x,nv):
        # 初めの札の合計がxで頂点nに到達可能か
        # x>sum(abc[0])は呼び出し前に満たしておく
        # 頂点1と頂点nvは攻略済み
        card=[x,x-2,1,1]
        card=select_card(card,abc[0])
        card=select_card(card,abc[nv])
        q=[]
        for v in g[0]:
            if v!=nv:
                heappush(q,[sum(abc[v]),v])
        for v in g[nv]:
            if v!=0:
                heappush(q,[sum(abc[v]),v])
        mi=set([0,nv])
        while q:
            s,v=heappop(q)
            if not s<card[0]:# 頂点vに勝てない
                break
            if v==n-1:return True
            card=select_card(card,abc[v])
            for v_ in g[v]:
                if v_ not in mi:
                    mi.add(v_)
                    heappush(q,[sum(abc[v_]),v_])
        return False
    
    while r-l>1:
        x=(r+l)//2
        ret=search(x,nv)
        if ret:
            l,r=l,x
        else:
            l,r=x,r
    for i in range(l,r+2):
        if search(i,nv):return i
    return -1
if __name__=='__main__':
    n,m=map(int,input().split())
    uv=[list(map(int,input().split())) for _ in range(m)]
    abc=[sorted(list(map(int,input().split()))) for _ in range(n)]
    ret=solv1(n,m,uv,abc)
    print(ret-2,1,1)
0