結果

問題 No.408 五輪ピック
ユーザー suppy193suppy193
提出日時 2016-11-02 14:34:43
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 497 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 11,572 KB
実行使用メモリ 22,956 KB
最終ジャッジ日時 2023-08-16 12:38:27
合計ジャッジ時間 12,246 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,172 KB
testcase_01 AC 77 ms
15,072 KB
testcase_02 AC 77 ms
15,144 KB
testcase_03 AC 78 ms
15,152 KB
testcase_04 AC 79 ms
15,172 KB
testcase_05 AC 157 ms
16,344 KB
testcase_06 AC 123 ms
16,780 KB
testcase_07 AC 147 ms
18,200 KB
testcase_08 AC 139 ms
16,076 KB
testcase_09 AC 135 ms
16,248 KB
testcase_10 AC 125 ms
18,060 KB
testcase_11 AC 128 ms
18,056 KB
testcase_12 AC 157 ms
19,576 KB
testcase_13 AC 155 ms
16,336 KB
testcase_14 AC 98 ms
15,984 KB
testcase_15 AC 160 ms
16,452 KB
testcase_16 AC 163 ms
16,864 KB
testcase_17 AC 171 ms
17,984 KB
testcase_18 AC 164 ms
17,300 KB
testcase_19 AC 166 ms
18,508 KB
testcase_20 AC 102 ms
15,956 KB
testcase_21 AC 93 ms
15,536 KB
testcase_22 AC 116 ms
16,472 KB
testcase_23 AC 169 ms
17,856 KB
testcase_24 AC 1,561 ms
16,824 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, m = gets.strip.split(' ').map(&:to_i)
#p n, m
@matrix = []
(1..n).each do |i|
	@matrix[i] = []
end

m.times do
	s, e = gets.strip.split(' ').map(&:to_i)	
	@matrix[s] << e
	@matrix[e] << s
end
#p @matrix

s = 1
path = [s]

def dfs(v, path)
	return if path.length > 5
	@matrix[v].each do |next_v|
		if next_v == 1 && path.length == 5
			puts "YES"
			exit
		end
		if @matrix[v].include?(next_v) && !path.include?(next_v)
			dfs(next_v, path.clone << next_v)
		end
	end
end

dfs(s, path)
puts "NO"
0