結果
問題 | No.1898 Battle and Exchange |
ユーザー | persimmon-persimmon |
提出日時 | 2022-04-14 15:25:30 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,332 bytes |
コンパイル時間 | 1,449 ms |
コンパイル使用メモリ | 86,676 KB |
実行使用メモリ | 187,768 KB |
最終ジャッジ日時 | 2023-08-25 21:07:08 |
合計ジャッジ時間 | 37,371 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
71,324 KB |
testcase_01 | AC | 75 ms
71,060 KB |
testcase_02 | AC | 75 ms
70,796 KB |
testcase_03 | AC | 75 ms
71,136 KB |
testcase_04 | AC | 101 ms
76,116 KB |
testcase_05 | AC | 100 ms
76,700 KB |
testcase_06 | AC | 150 ms
78,108 KB |
testcase_07 | AC | 140 ms
78,020 KB |
testcase_08 | AC | 129 ms
78,328 KB |
testcase_09 | AC | 242 ms
82,892 KB |
testcase_10 | AC | 76 ms
71,500 KB |
testcase_11 | AC | 114 ms
77,644 KB |
testcase_12 | AC | 167 ms
78,512 KB |
testcase_13 | AC | 75 ms
71,448 KB |
testcase_14 | AC | 165 ms
78,536 KB |
testcase_15 | AC | 77 ms
71,368 KB |
testcase_16 | AC | 144 ms
78,720 KB |
testcase_17 | AC | 300 ms
82,400 KB |
testcase_18 | AC | 870 ms
101,992 KB |
testcase_19 | AC | 1,627 ms
113,436 KB |
testcase_20 | AC | 916 ms
113,948 KB |
testcase_21 | AC | 4,019 ms
187,768 KB |
testcase_22 | AC | 111 ms
77,568 KB |
testcase_23 | AC | 133 ms
78,000 KB |
testcase_24 | AC | 137 ms
77,884 KB |
testcase_25 | AC | 168 ms
78,732 KB |
testcase_26 | AC | 86 ms
75,368 KB |
testcase_27 | AC | 186 ms
79,924 KB |
testcase_28 | AC | 197 ms
80,064 KB |
testcase_29 | AC | 238 ms
83,732 KB |
testcase_30 | AC | 178 ms
78,744 KB |
testcase_31 | AC | 117 ms
77,880 KB |
testcase_32 | AC | 807 ms
111,144 KB |
testcase_33 | AC | 1,586 ms
158,132 KB |
testcase_34 | AC | 641 ms
104,764 KB |
testcase_35 | AC | 1,065 ms
121,596 KB |
testcase_36 | AC | 616 ms
124,436 KB |
testcase_37 | AC | 904 ms
110,140 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 | -- | - |
ソースコード
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): ary=x+y ary.sort() return ary[-3:] # 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-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(range(n)) mi.discard(0) mi.discard(nv) while q: s,v=heappop(q) if not s<sum(card):# 頂点vに勝てない break if v==n-1:return True card=select_card(card,abc[v]) for v_ in g[v]: if v_ in mi: mi.discard(v_) heappush(q,[sum(abc[v_]),v_]) return n-1 not in mi while r-l>2: x=(r+l)//2 ret=search(x,nv) if ret: l,r=l,x else: l,r=x,r #print(ret,l,r,x) 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=[list(map(int,input().split())) for _ in range(n)] ret=solv1(n,m,uv,abc) print(ret-2,1,1)