結果
問題 | No.679 不思議マーケット |
ユーザー |
👑 |
提出日時 | 2023-11-24 23:51:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 522 bytes |
コンパイル時間 | 831 ms |
コンパイル使用メモリ | 82,140 KB |
実行使用メモリ | 72,832 KB |
最終ジャッジ日時 | 2024-09-26 09:50:16 |
合計ジャッジ時間 | 2,229 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
n, m = map(int, input().split()) edges = [[] for _ in range(n)] in_ = [0] * n for _ in range(m): g, r = map(int, input().split()) g -= 1 H = list(map(int, input().split())) for h in H: edges[h - 1].append(g) in_[g] += 1 ans = 0 st = [] ans = 0 for i in range(n): if in_[i] == 0: st.append(i) ans += 1 while st: pos = st.pop() for npos in edges[pos]: in_[npos] -= 1 if in_[npos] == 0: ans += 1 st.append(npos) print(ans)