結果

問題 No.679 不思議マーケット
ユーザー maimai
提出日時 2018-04-28 00:18:23
言語 Ruby
(3.3.0)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 555 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 11,508 KB
実行使用メモリ 15,808 KB
最終ジャッジ日時 2023-09-10 07:32:48
合計ジャッジ時間 2,820 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,200 KB
testcase_01 AC 78 ms
15,264 KB
testcase_02 AC 79 ms
15,216 KB
testcase_03 AC 87 ms
15,284 KB
testcase_04 AC 83 ms
15,308 KB
testcase_05 AC 91 ms
15,236 KB
testcase_06 AC 83 ms
15,088 KB
testcase_07 AC 82 ms
15,308 KB
testcase_08 AC 94 ms
15,300 KB
testcase_09 AC 78 ms
15,268 KB
testcase_10 AC 84 ms
15,244 KB
testcase_11 AC 82 ms
15,148 KB
testcase_12 AC 83 ms
15,212 KB
testcase_13 AC 86 ms
15,324 KB
testcase_14 AC 82 ms
15,248 KB
testcase_15 AC 237 ms
15,808 KB
testcase_16 AC 79 ms
15,268 KB
testcase_17 AC 81 ms
15,320 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:8: warning: assigned but unused variable - r
Syntax OK

ソースコード

diff #

def ascan; gets.split.map(&:to_i);end

N,M = ascan

items = {}

M.times do
    g,r = ascan
    hh = ascan
    items[g] = hh
end


ans = {}

det = {}

dfs = lambda do |id|
    next ans[id] if ans[id]
    item = items[id]
    next ans[id] = 1 if !item
    next false if det[id]
    det[id] = true
    ret = 1
    item.each do |e|
        r = dfs.call(e)
        if r == false
            ret = false
            break
        end
    end
    det[id] = false
    next ans[id] = ret
end

res = 0
(1..N).each do |id|
    res += dfs.call(id) ? 1 : 0
end

p res
0