結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
33,932 KB
testcase_01 AC 78 ms
15,036 KB
testcase_02 AC 82 ms
15,152 KB
testcase_03 AC 78 ms
15,228 KB
testcase_04 AC 79 ms
15,236 KB
testcase_05 AC 157 ms
16,440 KB
testcase_06 AC 124 ms
16,780 KB
testcase_07 AC 146 ms
18,032 KB
testcase_08 AC 137 ms
16,144 KB
testcase_09 AC 138 ms
16,452 KB
testcase_10 AC 126 ms
17,856 KB
testcase_11 AC 127 ms
17,980 KB
testcase_12 AC 159 ms
19,420 KB
testcase_13 AC 157 ms
16,220 KB
testcase_14 AC 100 ms
15,920 KB
testcase_15 AC 164 ms
16,312 KB
testcase_16 AC 163 ms
16,720 KB
testcase_17 AC 170 ms
18,056 KB
testcase_18 AC 164 ms
17,468 KB
testcase_19 AC 166 ms
18,572 KB
testcase_20 AC 103 ms
16,008 KB
testcase_21 AC 92 ms
15,596 KB
testcase_22 AC 116 ms
16,544 KB
testcase_23 AC 169 ms
17,976 KB
testcase_24 AC 1,562 ms
16,848 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 next_v != 1 && @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