結果

問題 No.583 鉄道同好会
ユーザー sca1lsca1l
提出日時 2017-10-30 17:20:39
言語 Ruby
(3.3.0)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 516 bytes
コンパイル時間 42 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-05-02 01:25:58
合計ジャッジ時間 3,289 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
12,288 KB
testcase_01 AC 73 ms
12,160 KB
testcase_02 AC 76 ms
12,160 KB
testcase_03 AC 75 ms
12,160 KB
testcase_04 AC 76 ms
12,288 KB
testcase_05 AC 75 ms
12,160 KB
testcase_06 AC 76 ms
12,160 KB
testcase_07 AC 76 ms
12,288 KB
testcase_08 AC 78 ms
12,032 KB
testcase_09 AC 77 ms
12,160 KB
testcase_10 AC 79 ms
12,416 KB
testcase_11 AC 117 ms
12,800 KB
testcase_12 AC 133 ms
13,056 KB
testcase_13 AC 135 ms
13,056 KB
testcase_14 AC 135 ms
13,056 KB
testcase_15 AC 157 ms
13,568 KB
testcase_16 AC 228 ms
14,080 KB
testcase_17 AC 255 ms
15,104 KB
testcase_18 AC 240 ms
15,232 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.pop
  x[now].each{|ne|
    next if ch[ne]
    q << ne
    ch[ne] = true
  }
  con+=1
end


if con<uni then
  puts 'NO'
  exit
end


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