結果

問題 No.630 門松グラフ
ユーザー simansiman
提出日時 2022-05-09 15:50:13
言語 Ruby
(3.3.0)
結果
AC  
実行時間 312 ms / 1,500 ms
コード長 513 bytes
コンパイル時間 39 ms
コンパイル使用メモリ 11,308 KB
実行使用メモリ 30,012 KB
最終ジャッジ日時 2023-09-23 14:21:03
合計ジャッジ時間 7,422 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,080 KB
testcase_01 AC 83 ms
15,276 KB
testcase_02 AC 81 ms
15,044 KB
testcase_03 AC 82 ms
15,116 KB
testcase_04 AC 83 ms
15,180 KB
testcase_05 AC 85 ms
15,336 KB
testcase_06 AC 83 ms
15,084 KB
testcase_07 AC 84 ms
15,044 KB
testcase_08 AC 83 ms
15,172 KB
testcase_09 AC 83 ms
15,284 KB
testcase_10 AC 84 ms
15,292 KB
testcase_11 AC 82 ms
15,280 KB
testcase_12 AC 83 ms
15,208 KB
testcase_13 AC 81 ms
15,296 KB
testcase_14 AC 83 ms
15,328 KB
testcase_15 AC 86 ms
15,256 KB
testcase_16 AC 82 ms
15,284 KB
testcase_17 AC 83 ms
15,352 KB
testcase_18 AC 85 ms
15,264 KB
testcase_19 AC 83 ms
15,164 KB
testcase_20 AC 312 ms
30,012 KB
testcase_21 AC 85 ms
15,124 KB
testcase_22 AC 306 ms
29,984 KB
testcase_23 AC 84 ms
15,344 KB
testcase_24 AC 184 ms
18,020 KB
testcase_25 AC 100 ms
17,668 KB
testcase_26 AC 181 ms
16,528 KB
testcase_27 AC 182 ms
17,896 KB
testcase_28 AC 297 ms
29,320 KB
testcase_29 AC 273 ms
25,824 KB
testcase_30 AC 249 ms
24,232 KB
testcase_31 AC 218 ms
21,916 KB
testcase_32 AC 178 ms
20,272 KB
testcase_33 AC 135 ms
16,312 KB
testcase_34 AC 185 ms
19,736 KB
testcase_35 AC 147 ms
17,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
E = Hash.new { |h, k| h[k] = [] }

if M < N - 1
  puts "NO"
  exit
end

m = M
cur = 0

(N - 1).times do |u|
  E[u] << u + 1
  m -= 1
end

while m > 0 && cur < N
  es = E[cur].size

  v = cur + 2 * es + 1

  if v < N
    E[cur] << v
    m -= 1
  else
    cur += 1
  end
end

if m > 0
  puts "NO"
else
  V = [*1..N]
  puts "YES"
  puts [*1..N].map { |v| v.even? ? V.shift : V.pop }.join(' ')

  E.each do |u, nums|
    nums.each do |v|
      puts "#{u + 1} #{v + 1}"
    end
  end
end
0