結果

問題 No.679 不思議マーケット
ユーザー Mr.Fuku
提出日時 2018-08-13 13:32:27
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 488 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-09-24 07:58:38
合計ジャッジ時間 1,332 ms
ジャッジサーバーID
(参考情報)
judge2 / 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
    if goods[i]!=[]:
        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())
    goods[g] = list(map(int,input().split()))

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

print(n-cnt)
0