結果

問題 No.1194 Replace
ユーザー titiatitia
提出日時 2020-08-22 16:55:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 898 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 63,132 KB
最終ジャッジ日時 2023-08-05 13:51:15
合計ジャッジ時間 16,396 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 640 ms
42,072 KB
testcase_01 AC 699 ms
43,540 KB
testcase_02 AC 562 ms
38,992 KB
testcase_03 AC 473 ms
36,120 KB
testcase_04 AC 704 ms
43,356 KB
testcase_05 AC 637 ms
41,760 KB
testcase_06 AC 586 ms
40,340 KB
testcase_07 AC 866 ms
63,016 KB
testcase_08 AC 874 ms
63,044 KB
testcase_09 AC 873 ms
63,072 KB
testcase_10 AC 866 ms
63,132 KB
testcase_11 AC 881 ms
63,092 KB
testcase_12 AC 898 ms
63,036 KB
testcase_13 AC 638 ms
39,956 KB
testcase_14 AC 518 ms
34,880 KB
testcase_15 AC 439 ms
32,696 KB
testcase_16 AC 599 ms
39,240 KB
testcase_17 AC 393 ms
27,400 KB
testcase_18 AC 397 ms
27,396 KB
testcase_19 AC 591 ms
39,320 KB
testcase_20 AC 16 ms
7,800 KB
testcase_21 AC 16 ms
7,768 KB
testcase_22 AC 16 ms
7,884 KB
testcase_23 AC 176 ms
18,728 KB
testcase_24 AC 65 ms
11,480 KB
testcase_25 AC 38 ms
9,244 KB
testcase_26 AC 218 ms
19,860 KB
testcase_27 AC 50 ms
9,736 KB
testcase_28 AC 109 ms
13,056 KB
testcase_29 AC 24 ms
8,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from operator import itemgetter

N,M=map(int,input().split())
E=dict()

for i in range(M):
    x,y=map(int,input().split())
    if y in E:
        E[y].append(x)
    else:
        E[y]=[x]

USESET=set()
SCORE=N*(N+1)//2

KEYS=sorted(E.keys(),reverse=True)

for i in KEYS:
    if i in USESET:
        continue

    Q=[i]
    while Q:
        x=Q.pop()
        if not (x in E):
            continue
        for to in E[x]:
            if to in USESET:
                continue
            else:
                USESET.add(to)
                if i>to:
                    SCORE+=i-to
                Q.append(to)

print(SCORE)
                
0