結果

問題 No.1194 Replace
ユーザー roarisroaris
提出日時 2020-08-22 17:37:14
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 530 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 86,720 KB
実行使用メモリ 823,168 KB
最終ジャッジ日時 2023-08-05 14:21:04
合計ジャッジ時間 4,611 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 MLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

def bfs(s):
    if ma[s]!=-1:
        return
    
    q = deque([s])
    ma[s] = s
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if ma[nv]==-1:
                ma[nv] = s
                q.append(nv)
        
N, M = map(int, input().split())
G = [[] for _ in range(N)]

for _ in range(M):
    B, C = map(int, input().split())
    G[C-1].append(B-1)

ma = [-1]*N

for i in range(N-1, -1, -1):
    bfs(i)
    
print(sum(ma)+N)
0