結果

問題 No.1194 Replace
ユーザー mkawa2mkawa2
提出日時 2021-07-06 00:44:12
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,138 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 270,388 KB
最終ジャッジ日時 2023-09-14 04:17:49
合計ジャッジ時間 31,944 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,224 ms
190,128 KB
testcase_01 AC 1,287 ms
194,764 KB
testcase_02 AC 1,048 ms
172,920 KB
testcase_03 AC 882 ms
148,792 KB
testcase_04 AC 1,291 ms
194,940 KB
testcase_05 AC 1,180 ms
187,388 KB
testcase_06 AC 1,124 ms
178,628 KB
testcase_07 AC 1,897 ms
266,284 KB
testcase_08 TLE -
testcase_09 AC 1,797 ms
269,732 KB
testcase_10 AC 1,817 ms
268,276 KB
testcase_11 AC 1,808 ms
270,288 KB
testcase_12 AC 1,794 ms
266,776 KB
testcase_13 AC 930 ms
129,836 KB
testcase_14 AC 820 ms
120,732 KB
testcase_15 AC 832 ms
125,972 KB
testcase_16 AC 916 ms
129,968 KB
testcase_17 AC 739 ms
119,392 KB
testcase_18 AC 638 ms
111,772 KB
testcase_19 AC 899 ms
137,452 KB
testcase_20 AC 91 ms
70,928 KB
testcase_21 AC 91 ms
71,268 KB
testcase_22 AC 90 ms
71,248 KB
testcase_23 AC 362 ms
97,788 KB
testcase_24 AC 248 ms
86,384 KB
testcase_25 AC 209 ms
80,068 KB
testcase_26 AC 420 ms
92,460 KB
testcase_27 AC 204 ms
79,764 KB
testcase_28 AC 308 ms
84,444 KB
testcase_29 AC 180 ms
79,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

from collections import defaultdict
from heapq import *

n, m = LI()
to = defaultdict(list)
uu = set()
for _ in range(m):
    u, v = LI()
    to[v].append(u)
    uu.add(u)
    uu.add(v)

dp = defaultdict(int)
hp = []
for u in uu:
    heappush(hp, (-u, u))
    dp[u] = u

while hp:
    d, u = heappop(hp)
    d = -d
    if d < dp[u]: continue
    for v in to[u]:
        if dp[v] >= d: continue
        dp[v] = d
        heappush(hp, (-d, v))
# print(dp)

ans = n*(n+1)//2
for u, d in dp.items():
    ans += d-u
print(ans)
0