結果

問題 No.679 不思議マーケット
ユーザー ああいいああいい
提出日時 2022-02-23 22:39:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 77,864 KB
最終ジャッジ日時 2023-09-14 15:57:24
合計ジャッジ時間 3,176 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,180 KB
testcase_01 AC 71 ms
71,336 KB
testcase_02 AC 71 ms
71,424 KB
testcase_03 AC 106 ms
77,072 KB
testcase_04 AC 94 ms
76,952 KB
testcase_05 AC 95 ms
77,096 KB
testcase_06 AC 100 ms
77,500 KB
testcase_07 AC 80 ms
71,416 KB
testcase_08 AC 95 ms
77,864 KB
testcase_09 AC 70 ms
71,404 KB
testcase_10 AC 86 ms
76,252 KB
testcase_11 AC 81 ms
71,536 KB
testcase_12 AC 94 ms
76,536 KB
testcase_13 AC 91 ms
76,556 KB
testcase_14 AC 90 ms
76,428 KB
testcase_15 AC 86 ms
75,356 KB
testcase_16 AC 71 ms
71,448 KB
testcase_17 AC 71 ms
71,272 KB
権限があれば一括ダウンロードができます

ソースコード

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