結果

問題 No.1194 Replace
ユーザー titiatitia
提出日時 2020-08-22 16:55:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,086 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 65,840 KB
最終ジャッジ日時 2024-04-23 11:02:13
合計ジャッジ時間 20,533 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 766 ms
44,756 KB
testcase_01 AC 843 ms
46,260 KB
testcase_02 AC 660 ms
41,468 KB
testcase_03 AC 670 ms
38,572 KB
testcase_04 AC 984 ms
46,104 KB
testcase_05 AC 779 ms
44,344 KB
testcase_06 AC 704 ms
42,988 KB
testcase_07 AC 1,032 ms
65,688 KB
testcase_08 AC 1,024 ms
65,780 KB
testcase_09 AC 1,056 ms
65,792 KB
testcase_10 AC 1,059 ms
65,604 KB
testcase_11 AC 1,086 ms
65,612 KB
testcase_12 AC 1,055 ms
65,840 KB
testcase_13 AC 803 ms
42,608 KB
testcase_14 AC 671 ms
37,296 KB
testcase_15 AC 589 ms
35,144 KB
testcase_16 AC 769 ms
42,016 KB
testcase_17 AC 545 ms
30,032 KB
testcase_18 AC 540 ms
29,852 KB
testcase_19 AC 771 ms
42,084 KB
testcase_20 AC 33 ms
10,752 KB
testcase_21 AC 32 ms
10,624 KB
testcase_22 AC 31 ms
10,624 KB
testcase_23 AC 238 ms
21,348 KB
testcase_24 AC 91 ms
14,120 KB
testcase_25 AC 60 ms
11,904 KB
testcase_26 AC 300 ms
22,464 KB
testcase_27 AC 73 ms
12,288 KB
testcase_28 AC 156 ms
15,780 KB
testcase_29 AC 48 ms
11,392 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