結果

問題 No.679 不思議マーケット
ユーザー 👑 rin204rin204
提出日時 2023-11-24 23:51:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 522 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 73,008 KB
最終ジャッジ日時 2023-11-24 23:51:07
合計ジャッジ時間 2,181 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 70 ms
73,008 KB
testcase_04 AC 61 ms
68,824 KB
testcase_05 AC 64 ms
68,868 KB
testcase_06 AC 66 ms
71,496 KB
testcase_07 AC 46 ms
55,588 KB
testcase_08 AC 62 ms
71,564 KB
testcase_09 AC 36 ms
53,460 KB
testcase_10 AC 51 ms
64,136 KB
testcase_11 AC 47 ms
57,636 KB
testcase_12 AC 59 ms
64,136 KB
testcase_13 AC 56 ms
66,492 KB
testcase_14 AC 54 ms
64,264 KB
testcase_15 AC 51 ms
63,192 KB
testcase_16 AC 36 ms
53,460 KB
testcase_17 AC 36 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0