結果

問題 No.1194 Replace
ユーザー H3PO4H3PO4
提出日時 2021-12-13 09:11:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 555 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 198,200 KB
最終ジャッジ日時 2023-09-29 09:46:06
合計ジャッジ時間 14,167 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 629 ms
197,176 KB
testcase_08 AC 670 ms
197,468 KB
testcase_09 AC 623 ms
196,692 KB
testcase_10 AC 581 ms
197,412 KB
testcase_11 AC 580 ms
196,768 KB
testcase_12 AC 569 ms
198,200 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 70 ms
71,228 KB
testcase_21 AC 69 ms
71,184 KB
testcase_22 AC 70 ms
71,204 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline

N, M = map(int, input().split())
BC = [tuple(map(int, input().split())) for _ in range(M)]

nodes = set()
for b, c in BC:
    nodes.add(b)
    nodes.add(c)
nodes = sorted(nodes)
comp = {x: i for i, x in enumerate(nodes)}
L = len(comp)

G = [[] for _ in range(L)]
for b, c in BC:
    G[comp[c]].append(comp[b])

table = nodes.copy()
for i in range(L - 1, -1, -1):
    x = table[i]
    for j in G[i]:
        if table[j] < x:
            table[j] = x
ans = N * (N + 1) // 2 - sum(nodes) + sum(table)
print(ans)
0