結果

問題 No.1194 Replace
ユーザー 37zigen37zigen
提出日時 2020-08-31 18:19:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,876 ms / 2,000 ms
コード長 481 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 76,532 KB
最終ジャッジ日時 2024-04-28 06:42:30
合計ジャッジ時間 36,051 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,512 ms
56,032 KB
testcase_01 AC 1,619 ms
63,344 KB
testcase_02 AC 1,202 ms
50,568 KB
testcase_03 AC 998 ms
45,528 KB
testcase_04 AC 1,580 ms
63,376 KB
testcase_05 AC 1,374 ms
55,164 KB
testcase_06 AC 1,313 ms
52,908 KB
testcase_07 AC 1,669 ms
76,464 KB
testcase_08 AC 1,630 ms
76,464 KB
testcase_09 AC 1,619 ms
76,280 KB
testcase_10 AC 1,636 ms
76,320 KB
testcase_11 AC 1,622 ms
76,492 KB
testcase_12 AC 1,687 ms
76,532 KB
testcase_13 AC 1,876 ms
61,604 KB
testcase_14 AC 1,709 ms
52,608 KB
testcase_15 AC 1,104 ms
43,016 KB
testcase_16 AC 1,832 ms
56,636 KB
testcase_17 AC 1,105 ms
41,488 KB
testcase_18 AC 1,188 ms
43,320 KB
testcase_19 AC 1,704 ms
55,524 KB
testcase_20 AC 31 ms
10,752 KB
testcase_21 AC 30 ms
10,624 KB
testcase_22 AC 31 ms
10,624 KB
testcase_23 AC 439 ms
25,268 KB
testcase_24 AC 123 ms
15,328 KB
testcase_25 AC 96 ms
13,440 KB
testcase_26 AC 708 ms
30,480 KB
testcase_27 AC 150 ms
14,464 KB
testcase_28 AC 308 ms
20,172 KB
testcase_29 AC 45 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
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