結果
| 問題 | 
                            No.1898 Battle and Exchange
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-03-20 01:24:00 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3,338 ms / 5,000 ms | 
| コード長 | 1,736 bytes | 
| コンパイル時間 | 191 ms | 
| コンパイル使用メモリ | 81,976 KB | 
| 実行使用メモリ | 203,492 KB | 
| 最終ジャッジ日時 | 2024-10-05 15:07:01 | 
| 合計ジャッジ時間 | 38,857 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 58 | 
ソースコード
import heapq
def solve(n, m, graph, abc):
    global ok
    def check(x):
        first = True
        #A = x, B = 1, C = 1で突破できる?
        myabc = [x, 1, 1]
        q = []
        good = [False] * n
        visit = [False] * n
        if sum(abc[0]) >= sum(myabc):
            return False
        myabc[1] = abc[0][0]
        good[0] = True
        visit[0] = True
        for to in graph[0]:
            visit[to] = True
            heapq.heappush(q, (sum(abc[to]), to))
        
        while q:
            nowsum, now = heapq.heappop(q)
            if nowsum < sum(myabc):
                good[now] = True
                if first:
                    first = False
                    myabc[2] = abc[0][1]
            else:
                return False
            if now != 0:
                myabc.sort(reverse=True)
                myabc[1] = max(myabc[1], abc[now][1])
                myabc[2] = max(myabc[2], abc[now][0])
            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
        return False
    ng = 3
    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)
ok = 0
abc = [list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    abc[i].sort(reverse = True)
    ok = max(ok , sum(abc[i]))
a, b, c = solve(n, m, graph, abc)
print(a, b, c)