結果

問題 No.1194 Replace
コンテスト
ユーザー roaris
提出日時 2020-08-22 17:37:14
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
RE  
実行時間 -
コード長 530 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 74 ms
コンパイル使用メモリ 81,116 KB
実行使用メモリ 1,331,840 KB
最終ジャッジ日時 2026-09-18 05:57:16
合計ジャッジ時間 3,207 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other RE * 2 MLE * 2 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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