結果

問題 No.583 鉄道同好会
ユーザー cielciel
提出日時 2017-10-29 17:40:14
言語 Ruby
(3.3.0)
結果
AC  
実行時間 438 ms / 2,000 ms
コード長 459 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 18,560 KB
最終ジャッジ日時 2024-05-01 22:15:41
合計ジャッジ時間 4,447 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
12,160 KB
testcase_01 AC 97 ms
12,160 KB
testcase_02 AC 100 ms
12,160 KB
testcase_03 AC 94 ms
12,160 KB
testcase_04 AC 98 ms
12,160 KB
testcase_05 AC 93 ms
12,288 KB
testcase_06 AC 98 ms
12,160 KB
testcase_07 AC 95 ms
12,416 KB
testcase_08 AC 98 ms
12,544 KB
testcase_09 AC 97 ms
12,416 KB
testcase_10 AC 93 ms
12,160 KB
testcase_11 AC 186 ms
18,560 KB
testcase_12 AC 213 ms
18,432 KB
testcase_13 AC 222 ms
18,304 KB
testcase_14 AC 224 ms
18,432 KB
testcase_15 AC 250 ms
18,304 KB
testcase_16 AC 367 ms
18,304 KB
testcase_17 AC 436 ms
18,560 KB
testcase_18 AC 438 ms
17,152 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:14: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
class UnionFind < Hash
	def root(a)
		self[a]=a if !has_key?(a)
		return self[a]==a ? a : (self[a]=root(self[a]))
	end
	def unite(a,b)
		x=root(a)
		y=root(b)
		self[x]=y
	end
end

n,m=gets.split.map(&:to_i)
deg=Hash.new 0
uf=UnionFind.new
m.times{
	a,b=gets.split.map(&:to_i)
	deg[a]^=1
	deg[b]^=1
	uf.unite(a,b)
}
puts uf.keys.all?{|k|uf.root(k)==uf.root(uf.each_key.next)}&&deg.values.all?{|e|e<=1}&&deg.values.count{|e|e==1}<3 ? :YES : :NO
0