結果

問題 No.1424 Ultrapalindrome
ユーザー simansiman
提出日時 2021-12-19 14:01:37
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 586 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 11,300 KB
実行使用メモリ 30,556 KB
最終ジャッジ日時 2023-10-13 18:43:18
合計ジャッジ時間 9,854 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,096 KB
testcase_01 AC 84 ms
15,140 KB
testcase_02 AC 84 ms
15,128 KB
testcase_03 AC 84 ms
15,172 KB
testcase_04 AC 84 ms
15,072 KB
testcase_05 AC 84 ms
15,056 KB
testcase_06 AC 84 ms
15,016 KB
testcase_07 AC 83 ms
15,236 KB
testcase_08 AC 84 ms
15,092 KB
testcase_09 AC 321 ms
25,092 KB
testcase_10 AC 321 ms
25,104 KB
testcase_11 AC 244 ms
21,428 KB
testcase_12 AC 318 ms
23,760 KB
testcase_13 AC 135 ms
16,812 KB
testcase_14 AC 261 ms
21,684 KB
testcase_15 AC 87 ms
15,180 KB
testcase_16 AC 222 ms
21,096 KB
testcase_17 AC 241 ms
21,504 KB
testcase_18 AC 213 ms
19,620 KB
testcase_19 AC 286 ms
20,824 KB
testcase_20 AC 124 ms
16,512 KB
testcase_21 AC 253 ms
22,168 KB
testcase_22 AC 182 ms
18,312 KB
testcase_23 AC 102 ms
15,696 KB
testcase_24 AC 125 ms
17,204 KB
testcase_25 AC 119 ms
16,616 KB
testcase_26 AC 352 ms
23,176 KB
testcase_27 AC 382 ms
24,648 KB
testcase_28 AC 352 ms
24,340 KB
testcase_29 RE -
testcase_30 AC 401 ms
25,024 KB
testcase_31 AC 443 ms
25,768 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

cnt = E.map { |_, list| list.size }.count { |x| x >= 3 }
if cnt >= 2
  puts 'No'
  exit
elsif cnt == 0
  puts 'Yes'
  exit
end

root = (1..N).find { |v| E[v].size >= 3 }
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