結果

問題 No.583 鉄道同好会
ユーザー sca1lsca1l
提出日時 2017-10-27 23:31:48
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 462 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 20,480 KB
最終ジャッジ日時 2024-05-01 17:51:31
合計ジャッジ時間 9,784 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
17,792 KB
testcase_01 AC 85 ms
12,160 KB
testcase_02 AC 84 ms
12,416 KB
testcase_03 AC 86 ms
12,160 KB
testcase_04 AC 88 ms
12,160 KB
testcase_05 AC 85 ms
12,160 KB
testcase_06 AC 83 ms
12,288 KB
testcase_07 AC 84 ms
12,288 KB
testcase_08 AC 84 ms
12,288 KB
testcase_09 AC 84 ms
12,288 KB
testcase_10 AC 85 ms
12,160 KB
testcase_11 AC 586 ms
13,184 KB
testcase_12 AC 893 ms
14,080 KB
testcase_13 AC 926 ms
14,080 KB
testcase_14 AC 896 ms
14,208 KB
testcase_15 AC 1,392 ms
14,720 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = 0
odd = 0
x.each{|t|
  s = t.size
  uni += 1 if s>0
  odd += 1 if s%2==1
}

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


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