結果

問題 No.679 不思議マーケット
ユーザー ああいい
提出日時 2022-02-23 22:39:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 74,104 KB
最終ジャッジ日時 2024-07-01 23:06:33
合計ジャッジ時間 2,085 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
G = [[] for _ in range(n+1)]
Gnum = [0] * (n+1)
for _ in range(m):
    g,r = map(int,input().split())
    h = list(map(int,input().split()))
    for k in h:
        G[k].append(g)
        Gnum[g] += 1
top = []
ans = 0
for i in range(1,n+1):
    if Gnum[i] == 0:
        top.append(i)
        ans += 1
while top:
    now = top.pop()
    for v in G[now]:
        Gnum[v] -= 1
        if Gnum[v] == 0:
            top.append(v)
            ans += 1
print(ans)
0