結果

問題 No.1424 Ultrapalindrome
ユーザー simansiman
提出日時 2021-12-19 12:44:51
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 458 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 11,504 KB
実行使用メモリ 29,724 KB
最終ジャッジ日時 2023-10-13 18:39:27
合計ジャッジ時間 11,637 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,012 KB
testcase_01 AC 83 ms
15,056 KB
testcase_02 AC 83 ms
15,176 KB
testcase_03 AC 83 ms
15,300 KB
testcase_04 AC 84 ms
15,104 KB
testcase_05 AC 84 ms
15,228 KB
testcase_06 AC 82 ms
15,128 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 350 ms
24,588 KB
testcase_10 AC 349 ms
24,416 KB
testcase_11 AC 252 ms
20,836 KB
testcase_12 AC 330 ms
24,156 KB
testcase_13 AC 138 ms
16,944 KB
testcase_14 AC 271 ms
21,260 KB
testcase_15 AC 84 ms
15,060 KB
testcase_16 AC 227 ms
20,808 KB
testcase_17 AC 258 ms
21,408 KB
testcase_18 AC 192 ms
19,728 KB
testcase_19 AC 248 ms
20,392 KB
testcase_20 AC 119 ms
16,628 KB
testcase_21 AC 229 ms
23,572 KB
testcase_22 AC 163 ms
18,016 KB
testcase_23 AC 100 ms
15,728 KB
testcase_24 AC 118 ms
17,920 KB
testcase_25 AC 114 ms
16,856 KB
testcase_26 AC 312 ms
23,372 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 371 ms
24,264 KB
testcase_31 AC 383 ms
24,300 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
E = Hash.new { |h, k| h[k] = [] }

(N - 1).times do
  a, b = gets.split.map(&:to_i)
  E[a] << b
  E[b] << a
end

root = (1..N).find { |v| E[v].size == 1 }
counter = Hash.new(0)

def dfs(v, dist, counter, parent = -1)
  if dist > 0 && E[v].size == 1
    counter[dist] += 1
  end

  E[v].each do |u|
    next if u == parent
    dfs(u, dist + 1, counter, v)
  end
end

dfs(root, 0, counter)

if counter.size >= 2
  puts 'No'
else
  puts 'Yes'
end
0