結果

問題 No.583 鉄道同好会
ユーザー simansiman
提出日時 2021-11-03 08:44:33
言語 Ruby
(3.3.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2024-04-20 22:16:04
合計ジャッジ時間 3,899 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
12,160 KB
testcase_01 AC 89 ms
12,288 KB
testcase_02 AC 82 ms
12,288 KB
testcase_03 AC 88 ms
12,288 KB
testcase_04 AC 82 ms
12,160 KB
testcase_05 AC 80 ms
12,288 KB
testcase_06 AC 82 ms
12,160 KB
testcase_07 AC 81 ms
12,160 KB
testcase_08 AC 81 ms
12,288 KB
testcase_09 AC 77 ms
12,160 KB
testcase_10 AC 80 ms
12,288 KB
testcase_11 AC 141 ms
13,184 KB
testcase_12 AC 161 ms
13,952 KB
testcase_13 AC 154 ms
14,208 KB
testcase_14 AC 156 ms
14,208 KB
testcase_15 AC 177 ms
14,592 KB
testcase_16 AC 256 ms
16,384 KB
testcase_17 AC 297 ms
17,664 KB
testcase_18 AC 294 ms
17,664 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
E = Hash.new { |h, k| h[k] = [] }

M.times do
  a, b = gets.split.map(&:to_i)
  E[a] << b
  E[b] << a
end

def is_connected_graph?
  queue = []
  queue << E.first.first
  visited = Array.new(N + 1, false)
  cnt = 0

  until queue.empty?
    v = queue.shift

    next if visited[v]
    visited[v] = true
    cnt += 1

    E[v].each do |u|
      queue << u
    end
  end

  cnt == E.size
end

def f
  E.all? { |u, list| list.size.even? }
end

def g
  odd_cnt = 0
  even_cnt = 0

  E.each do |u, list|
    if list.size.even?
      even_cnt += 1
    else
      odd_cnt += 1
    end
  end

  odd_cnt == 2
end

if is_connected_graph? && (f || g)
  puts 'YES'
else
  puts 'NO'
end
0