結果
問題 | No.1898 Battle and Exchange |
ユーザー | polylogK |
提出日時 | 2021-12-27 00:54:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 607 ms / 5,000 ms |
コード長 | 1,652 bytes |
コンパイル時間 | 363 ms |
コンパイル使用メモリ | 81,848 KB |
実行使用メモリ | 105,944 KB |
最終ジャッジ日時 | 2024-11-14 10:07:32 |
合計ジャッジ時間 | 23,701 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
54,596 KB |
testcase_01 | AC | 38 ms
53,188 KB |
testcase_02 | AC | 40 ms
54,388 KB |
testcase_03 | AC | 40 ms
53,628 KB |
testcase_04 | AC | 47 ms
56,940 KB |
testcase_05 | AC | 48 ms
56,728 KB |
testcase_06 | AC | 60 ms
65,164 KB |
testcase_07 | AC | 56 ms
64,440 KB |
testcase_08 | AC | 43 ms
55,112 KB |
testcase_09 | AC | 139 ms
78,056 KB |
testcase_10 | AC | 40 ms
53,348 KB |
testcase_11 | AC | 41 ms
55,352 KB |
testcase_12 | AC | 67 ms
71,608 KB |
testcase_13 | AC | 40 ms
53,200 KB |
testcase_14 | AC | 68 ms
70,972 KB |
testcase_15 | AC | 40 ms
53,420 KB |
testcase_16 | AC | 56 ms
63,608 KB |
testcase_17 | AC | 154 ms
78,692 KB |
testcase_18 | AC | 208 ms
82,976 KB |
testcase_19 | AC | 244 ms
85,100 KB |
testcase_20 | AC | 237 ms
85,732 KB |
testcase_21 | AC | 425 ms
97,756 KB |
testcase_22 | AC | 41 ms
54,664 KB |
testcase_23 | AC | 54 ms
63,188 KB |
testcase_24 | AC | 53 ms
62,840 KB |
testcase_25 | AC | 73 ms
73,996 KB |
testcase_26 | AC | 40 ms
54,248 KB |
testcase_27 | AC | 75 ms
76,084 KB |
testcase_28 | AC | 80 ms
76,444 KB |
testcase_29 | AC | 92 ms
76,792 KB |
testcase_30 | AC | 69 ms
72,100 KB |
testcase_31 | AC | 46 ms
55,888 KB |
testcase_32 | AC | 198 ms
84,308 KB |
testcase_33 | AC | 273 ms
90,156 KB |
testcase_34 | AC | 182 ms
83,196 KB |
testcase_35 | AC | 224 ms
86,624 KB |
testcase_36 | AC | 210 ms
85,728 KB |
testcase_37 | AC | 177 ms
80,200 KB |
testcase_38 | AC | 607 ms
105,944 KB |
testcase_39 | AC | 411 ms
99,736 KB |
testcase_40 | AC | 561 ms
101,732 KB |
testcase_41 | AC | 372 ms
97,212 KB |
testcase_42 | AC | 156 ms
78,700 KB |
testcase_43 | AC | 309 ms
93,428 KB |
testcase_44 | AC | 42 ms
54,352 KB |
testcase_45 | AC | 166 ms
79,628 KB |
testcase_46 | AC | 251 ms
84,932 KB |
testcase_47 | AC | 158 ms
79,080 KB |
testcase_48 | AC | 168 ms
79,840 KB |
testcase_49 | AC | 87 ms
76,732 KB |
testcase_50 | AC | 81 ms
76,400 KB |
testcase_51 | AC | 80 ms
76,416 KB |
testcase_52 | AC | 84 ms
76,380 KB |
testcase_53 | AC | 188 ms
80,568 KB |
testcase_54 | AC | 189 ms
81,920 KB |
testcase_55 | AC | 219 ms
81,976 KB |
testcase_56 | AC | 215 ms
82,588 KB |
testcase_57 | AC | 553 ms
99,912 KB |
testcase_58 | AC | 503 ms
99,724 KB |
testcase_59 | AC | 460 ms
99,732 KB |
testcase_60 | AC | 499 ms
100,152 KB |
ソースコード
import heapq def solve(n, m, graph, abc): for i in range(n): abc[i].sort(reverse=True) ans = sum(abc[0]) - 1 myabc = [ans, 1, 1] myabc[1] = abc[0][0] v = graph[0][0] for to in graph[0]: if sum(abc[to]) < sum(abc[v]): v = to if sum(abc[v]) >= sum(myabc): ans += sum(abc[v]) - sum(myabc) + 1 myabc = [ans, 1, 1] q, visit = [], [False] * n heapq.heappush(q, (sum(abc[0]), 0)) visit[0] = True while q: nowsum, now = heapq.heappop(q) if nowsum >= sum(myabc): diff = nowsum - sum(myabc) + 1 if myabc[0] == ans: ans += diff myabc[0] += diff elif myabc[1] == ans: ans += diff myabc[1] += diff elif myabc[2] == ans: ans += diff myabc[2] += diff else: ans = myabc[2] + diff myabc[2] += diff if now == n - 1: return ans, 1, 1 myabc += abc[now] myabc.sort(reverse=True) myabc = myabc[:3] for to in graph[now]: if visit[to]: continue visit[to] = True heapq.heappush(q, (sum(abc[to]), to)) if __name__ == '__main__': 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)] a, b, c = solve(n, m, graph, abc) print(a, b, c)