結果

問題 No.679 不思議マーケット
ユーザー cielciel
提出日時 2018-04-30 23:42:00
言語 Ruby
(3.3.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 386 bytes
コンパイル時間 64 ms
コンパイル使用メモリ 11,464 KB
実行使用メモリ 15,692 KB
最終ジャッジ日時 2023-09-10 08:33:36
合計ジャッジ時間 2,491 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,168 KB
testcase_01 AC 82 ms
15,212 KB
testcase_02 AC 82 ms
15,052 KB
testcase_03 AC 93 ms
15,476 KB
testcase_04 AC 88 ms
15,088 KB
testcase_05 AC 88 ms
15,400 KB
testcase_06 AC 83 ms
15,220 KB
testcase_07 AC 84 ms
15,136 KB
testcase_08 AC 86 ms
15,344 KB
testcase_09 AC 80 ms
15,264 KB
testcase_10 AC 83 ms
15,312 KB
testcase_11 AC 83 ms
15,268 KB
testcase_12 AC 85 ms
15,544 KB
testcase_13 AC 85 ms
15,048 KB
testcase_14 AC 85 ms
15,056 KB
testcase_15 AC 84 ms
15,692 KB
testcase_16 AC 81 ms
15,328 KB
testcase_17 AC 80 ms
15,056 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:19: warning: assigned but unused variable - r
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
def cycle(c,m,f,h)
	return f[c] if f[c]!=nil
	q=true
	h[c].each{|e|
		if m.has_key?(e)
			q=false
		else
			m[e]=1
			q=false if !cycle(e,m,f,h)
			m.delete e
		end
	}
	f[c]=q
end
n,m=gets.split.map &:to_i
h=Hash.new{|h,k|h[k]=[]}
m.times{
g,r=gets.split.map &:to_i
gets.split.map(&:to_i).each{|e|h[g-1]<<e-1}
}
f=[nil]*n
n.times{|i|cycle(i,{i=>1},f,h)}
p f.count(true)
0