結果

問題 No.1194 Replace
ユーザー 37zigen37zigen
提出日時 2020-08-31 18:17:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 441 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 76,532 KB
最終ジャッジ日時 2024-04-28 06:38:45
合計ジャッジ時間 31,681 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 1,146 ms
50,560 KB
testcase_03 AC 924 ms
45,424 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 1,598 ms
76,336 KB
testcase_08 AC 1,626 ms
76,468 KB
testcase_09 AC 1,586 ms
76,532 KB
testcase_10 AC 1,588 ms
76,268 KB
testcase_11 AC 1,591 ms
76,472 KB
testcase_12 AC 1,615 ms
76,400 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 30 ms
10,624 KB
testcase_21 AC 30 ms
10,752 KB
testcase_22 AC 30 ms
10,624 KB
testcase_23 AC 414 ms
25,216 KB
testcase_24 AC 124 ms
15,192 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 45 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
g=dict()
e=[]
for i in range(M):
    b,c=map(int,input().split())
    e.append((c,b))
    g[c]=[]
for a,b in e:
    g[a].append(b)
e.sort(reverse=True)
to=dict()
ans=N*(N+1)//2

def dfs(cur,v):
    global ans
    for dst in g[cur]:
        if dst in to or dst>v:
            continue
        to[dst]=v
        ans+=v-dst
        if dst in g:
            dfs(dst,v)

for src,tmp in e:
    dfs(src,src)

print(ans)
0