結果
| 問題 |
No.1898 Battle and Exchange
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-12 17:57:10 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,586 bytes |
| コンパイル時間 | 373 ms |
| コンパイル使用メモリ | 13,056 KB |
| 実行使用メモリ | 66,688 KB |
| 最終ジャッジ日時 | 2024-11-14 10:09:04 |
| 合計ジャッジ時間 | 90,835 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 WA * 9 TLE * 9 |
ソースコード
import heapq
def solve(n, m, graph, abc):
for i in range(n):
abc[i].sort(reverse = True)
def check(x):
#A = x, B = 1, C = 1で突破できる?
a = x
b = 1
c = 1
q = []
good = [False] * n
visit = [False] * n
if sum(abc[0]) >= a + b + c:
return False
b = abc[0][0]
good[0] = True
visit[0] = True
for to in graph[0]:
visit[to] = True
heapq.heappush(q, (sum(abc[to]), to))
if not q:
return False
else:
c = max(c, abc[0][1])
while q:
nowsum, now = heapq.heappop(q)
if nowsum < a + b + c:
good[now] = True
if b > c:
b, c = c, b
b = max(b, abc[now][0])
c = max(c, abc[now][1])
for to in graph[now]:
if not visit[to]:
visit[to] = True
heapq.heappush(q, (sum(abc[to]), to))
if good[n - 1]:
return True
else:
return False
ok = 3 * 10 ** 9
ng = 1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if check(mid):
ok = mid
else:
ng = mid
return ok, 1, 1
n, m = map(int,input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
u, v = map(int,input().split())
u -= 1
v -= 1
graph[u].append(v)
graph[v].append(u)
abc = [list(map(int,input().split())) for _ in range(n)]
print(*solve(n, m, graph, abc))