結果

問題 No.583 鉄道同好会
ユーザー 0w10w1
提出日時 2017-11-01 23:21:50
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 407 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 25,344 KB
最終ジャッジ日時 2024-05-02 04:21:37
合計ジャッジ時間 7,891 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 75 ms
12,160 KB
testcase_02 AC 76 ms
12,160 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 74 ms
12,288 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 75 ms
12,288 KB
testcase_09 AC 74 ms
12,288 KB
testcase_10 AC 77 ms
12,416 KB
testcase_11 AC 363 ms
16,128 KB
testcase_12 AC 473 ms
16,640 KB
testcase_13 AC 479 ms
16,640 KB
testcase_14 AC 476 ms
16,512 KB
testcase_15 AC 589 ms
18,432 KB
testcase_16 AC 1,061 ms
24,832 KB
testcase_17 AC 1,268 ms
24,960 KB
testcase_18 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 || anc.delete(-1).uniq.size > 1 ? :NO : :YES
0