結果
問題 |
No.1194 Replace
|
ユーザー |
|
提出日時 | 2020-08-22 17:37:14 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 530 bytes |
コンパイル時間 | 217 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 847,616 KB |
最終ジャッジ日時 | 2024-10-15 11:26:03 |
合計ジャッジ時間 | 2,899 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | RE * 2 MLE * 1 -- * 24 |
ソースコード
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)