結果

問題 No.679 不思議マーケット
ユーザー Mr.Fuku
提出日時 2018-08-13 12:40:35
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 526 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-09-24 07:57:57
合計ジャッジ時間 1,372 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
goods = [[]for i in range(n+1)]

def search(i):
    if goods[i]==-1:
        return False
    else:
        tmp = goods[i][:]
        goods[i] = -1
        for j in tmp:
            if search(j):goods[j]=[]
            else:
                return False
        return True

for i in range(m):
    g,r = map(int,input().split())
    h = list(map(int,input().split()))
    goods[g] = h

cnt = 0
for i in range(1,n+1):
    if search(i):
        goods[i] = []
    else:
        cnt+=1

print(n-cnt)
0