結果
| 問題 | No.1898 Battle and Exchange |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-04-08 22:58:22 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,137 bytes |
| 記録 | |
| コンパイル時間 | 239 ms |
| コンパイル使用メモリ | 82,532 KB |
| 実行使用メモリ | 181,664 KB |
| 最終ジャッジ日時 | 2024-11-28 13:59:54 |
| 合計ジャッジ時間 | 39,830 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 46 WA * 12 |
ソースコード
"""
最初に持つ数は
1 1 x
でいい
交換も一番小さいのと大きいのでいい
にぶたん
"""
from heapq import*
n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
u, v = map(int, input().split())
u -= 1
v -= 1
edges[u].append(v)
edges[v].append(u)
tot = [0] * n
max_ = [0] * n
for i in range(n):
a, b, c = map(int, input().split())
tot[i] = a + b + c
max_[i] = max(a, b, c)
def ok(x):
hq = [(tot[0], 0)]
used = [False] * n
used[0] = True
a, b, c = x, 1, 1
while hq:
t, pos = heappop(hq)
if t >= a + b + c:
return False
for npos in edges[pos]:
if not used[npos]:
used[npos] = True
heappush(hq, (tot[npos], npos))
ma = max_[npos]
if ma > c:
c = ma
if c > b:
b, c = c, b
if b > a:
a, b = b, a
return True
l = 1
r = 3 * 10 ** 8
while r - l > 1:
mid = (l + r) // 2
if ok(mid):
r = mid
else:
l = mid
print(1, 1, r)