結果

問題 No.583 鉄道同好会
ユーザー sca1lsca1l
提出日時 2017-10-27 23:27:44
言語 Ruby
(3.4.1)
結果
TLE  
実行時間 -
コード長 452 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 28,544 KB
最終ジャッジ日時 2024-11-21 23:22:58
合計ジャッジ時間 15,777 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 TLE * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n,m = gets.split.map(&:to_i)
x = n.times.map{[]}
at = 0
m.times{
  a,b=gets.split.map(&:to_i)
  at=a
  x[a]<<b
  x[b]<<a
}

uni = x.select{|t| t.size>0}.size

con = 0
q = [at]
ch = Array.new(n, false)
while q.size>0
  now = q.shift
  ch[now] = true
  x[now].each{|ne|
    next if ch[ne]
    q<<ne
  }
  con+=1
end


if con<uni then
  puts 'NO'
  exit
end

odd = x.select{|t| t.size%2==1}.size

if odd==0 || odd==2 then
  puts 'YES'
else
  puts 'NO'
end
0