結果

問題 No.583 鉄道同好会
ユーザー sca1lsca1l
提出日時 2017-10-30 17:17:39
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 464 bytes
コンパイル時間 47 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2024-05-02 01:25:51
合計ジャッジ時間 8,228 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
17,664 KB
testcase_01 AC 79 ms
12,160 KB
testcase_02 AC 75 ms
12,160 KB
testcase_03 AC 74 ms
12,160 KB
testcase_04 AC 73 ms
12,160 KB
testcase_05 AC 75 ms
12,288 KB
testcase_06 AC 76 ms
12,160 KB
testcase_07 AC 75 ms
12,160 KB
testcase_08 AC 74 ms
12,160 KB
testcase_09 AC 75 ms
12,160 KB
testcase_10 AC 76 ms
12,288 KB
testcase_11 AC 332 ms
12,928 KB
testcase_12 AC 554 ms
13,312 KB
testcase_13 AC 567 ms
13,440 KB
testcase_14 AC 554 ms
13,312 KB
testcase_15 AC 822 ms
13,952 KB
testcase_16 TLE -
testcase_17 TLE -
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.pop
  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