結果

問題 No.583 鉄道同好会
ユーザー 0w10w1
提出日時 2017-11-01 23:21:01
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 375 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 25,088 KB
最終ジャッジ日時 2024-05-02 04:20:59
合計ジャッジ時間 10,016 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
12,160 KB
testcase_01 AC 92 ms
12,160 KB
testcase_02 AC 92 ms
12,288 KB
testcase_03 AC 91 ms
12,032 KB
testcase_04 WA -
testcase_05 AC 92 ms
12,032 KB
testcase_06 AC 92 ms
12,160 KB
testcase_07 AC 90 ms
12,032 KB
testcase_08 AC 93 ms
12,160 KB
testcase_09 AC 93 ms
12,032 KB
testcase_10 AC 100 ms
12,160 KB
testcase_11 AC 441 ms
16,256 KB
testcase_12 AC 609 ms
16,640 KB
testcase_13 AC 564 ms
16,640 KB
testcase_14 AC 578 ms
16,512 KB
testcase_15 AC 734 ms
18,176 KB
testcase_16 AC 1,350 ms
24,832 KB
testcase_17 AC 1,714 ms
24,704 KB
testcase_18 AC 1,701 ms
25,088 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map &:to_i
S = $<.map { |s| eval "[%d, %d].sort" % s.split }
deg = [0] * N
S.each { |t| deg[t[0]] += 1; deg[t[1]] += 1 }
odd = (0...N).select { |i| deg[i] % 2 == 1 }
uf = [-1] * N
S.each { |t| uf[t[0]] = t[0]; uf[t[1]] = t[1] }
anc = lambda { |v| uf[v] == v ? v : uf[v] = anc[uf[v]] }
S.each { |t| uf[anc[t[0]]] = anc[t[1]] }
puts odd.size > 2 ? :NO : :YES
0