結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-01-31 23:03:25
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 444 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 11,936 KB
実行使用メモリ 48,920 KB
最終ジャッジ日時 2023-10-17 11:57:37
合計ジャッジ時間 7,132 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
16,120 KB
testcase_01 AC 88 ms
16,120 KB
testcase_02 AC 84 ms
16,120 KB
testcase_03 AC 86 ms
16,120 KB
testcase_04 AC 87 ms
16,120 KB
testcase_05 AC 86 ms
16,120 KB
testcase_06 AC 87 ms
16,120 KB
testcase_07 AC 86 ms
16,120 KB
testcase_08 AC 87 ms
16,120 KB
testcase_09 AC 87 ms
16,120 KB
testcase_10 WA -
testcase_11 AC 87 ms
16,120 KB
testcase_12 AC 88 ms
16,120 KB
testcase_13 WA -
testcase_14 AC 130 ms
18,568 KB
testcase_15 AC 128 ms
18,576 KB
testcase_16 WA -
testcase_17 AC 128 ms
18,864 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 337 ms
30,968 KB
testcase_21 AC 526 ms
40,844 KB
testcase_22 AC 668 ms
45,828 KB
testcase_23 AC 710 ms
46,600 KB
testcase_24 AC 713 ms
48,920 KB
testcase_25 AC 719 ms
48,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.chomp.to_i
b = {}
(n-1).times do
  u, v = gets.chomp.split.map(&:to_i)

  b[u] ||= []
  b[u] << v
  b[v] ||= []
  b[v] << u
end
visited = [0]
mins = [0xffffffff] * n
q = []
b.keys.each do |key|
  q << [key, 0]
end
until q.empty?
  p, c = q.shift

  next if b[p].nil?
  b[p].each do |bi|
    next if c + 1 > mins[bi]

    mins[bi] = c + 1
    visited << bi
    q.push([bi, c + 1])
  end
end
puts visited.uniq.size == n ? 'Bob' : 'Alice'
0