結果
| 問題 |
No.583 鉄道同好会
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-11-03 08:44:33 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 303 ms / 2,000 ms |
| コード長 | 704 bytes |
| コンパイル時間 | 164 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 17,408 KB |
| 最終ジャッジ日時 | 2024-10-12 20:34:08 |
| 合計ジャッジ時間 | 3,548 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
コンパイルメッセージ
Syntax OK
ソースコード
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
siman