結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-01-31 23:10:24
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 420 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 11,792 KB
実行使用メモリ 35,072 KB
最終ジャッジ日時 2023-10-17 12:14:12
合計ジャッジ時間 6,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,976 KB
testcase_01 AC 87 ms
15,976 KB
testcase_02 AC 87 ms
15,976 KB
testcase_03 AC 88 ms
15,976 KB
testcase_04 AC 87 ms
15,976 KB
testcase_05 AC 87 ms
15,976 KB
testcase_06 AC 87 ms
15,976 KB
testcase_07 AC 87 ms
15,976 KB
testcase_08 AC 86 ms
15,976 KB
testcase_09 AC 86 ms
15,976 KB
testcase_10 WA -
testcase_11 AC 88 ms
15,976 KB
testcase_12 AC 87 ms
15,976 KB
testcase_13 AC 117 ms
17,340 KB
testcase_14 AC 120 ms
17,244 KB
testcase_15 AC 120 ms
17,248 KB
testcase_16 AC 117 ms
17,336 KB
testcase_17 AC 117 ms
17,336 KB
testcase_18 AC 184 ms
20,960 KB
testcase_19 WA -
testcase_20 AC 216 ms
21,940 KB
testcase_21 AC 298 ms
24,768 KB
testcase_22 AC 360 ms
25,936 KB
testcase_23 AC 486 ms
34,816 KB
testcase_24 AC 478 ms
35,072 KB
testcase_25 AC 509 ms
34,812 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.first, 0]]
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