結果

問題 No.583 鉄道同好会
ユーザー 0w10w1
提出日時 2017-11-01 23:33:26
言語 Ruby
(3.3.0)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 433 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 19,840 KB
最終ジャッジ日時 2024-05-02 04:23:34
合計ジャッジ時間 3,561 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
12,288 KB
testcase_01 AC 74 ms
12,288 KB
testcase_02 AC 84 ms
12,160 KB
testcase_03 AC 76 ms
12,288 KB
testcase_04 AC 74 ms
12,160 KB
testcase_05 AC 75 ms
12,160 KB
testcase_06 AC 74 ms
12,288 KB
testcase_07 AC 76 ms
12,160 KB
testcase_08 AC 78 ms
12,032 KB
testcase_09 AC 74 ms
12,288 KB
testcase_10 AC 74 ms
12,288 KB
testcase_11 AC 142 ms
14,208 KB
testcase_12 AC 169 ms
15,232 KB
testcase_13 AC 173 ms
15,232 KB
testcase_14 AC 171 ms
15,104 KB
testcase_15 AC 199 ms
15,232 KB
testcase_16 AC 301 ms
19,072 KB
testcase_17 AC 359 ms
19,840 KB
testcase_18 AC 355 ms
19,584 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map &:to_i
S = $<.map { |s| s.split.map(&:to_i).sort }
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 || uf.reject { |v| v == -1 } .map { |v| anc[v] } .uniq.size > 1 ? :NO : :YES
0