結果
問題 | No.1898 Battle and Exchange |
ユーザー |
👑 |
提出日時 | 2022-04-08 23:06:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,197 ms / 5,000 ms |
コード長 | 1,335 bytes |
コンパイル時間 | 380 ms |
コンパイル使用メモリ | 82,564 KB |
実行使用メモリ | 180,580 KB |
最終ジャッジ日時 | 2024-11-28 14:13:54 |
合計ジャッジ時間 | 43,100 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 58 |
ソースコード
""" 最初に持つ数は 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 A = [0] * n B = [0] * n C = [0] * n for i in range(n): A[i], B[i], C[i] = map(int, input().split()) tot[i] = A[i] + B[i] + C[i] def ok(x): if x + 2 <= A[0] + B[0] + C[0]: return False t = x + max(A[0], B[0], C[0]) + 1 ok = False for npos in edges[0]: if t > A[npos] + B[npos] + C[npos]: ok = True break if not ok: return False 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)) lst = [a, b, c, A[pos], B[pos], C[pos]] lst.sort() a, b, c = lst[3:] 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)