結果

問題 No.1424 Ultrapalindrome
ユーザー 👑 obakyanobakyan
提出日時 2021-05-27 21:37:52
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 17,152 KB
最終ジャッジ日時 2024-04-24 07:24:22
合計ジャッジ時間 2,619 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 57 ms
12,032 KB
testcase_10 AC 57 ms
12,032 KB
testcase_11 AC 37 ms
8,960 KB
testcase_12 AC 50 ms
11,392 KB
testcase_13 AC 15 ms
5,376 KB
testcase_14 AC 43 ms
9,600 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 32 ms
8,320 KB
testcase_17 AC 42 ms
9,216 KB
testcase_18 AC 36 ms
8,448 KB
testcase_19 AC 52 ms
10,112 KB
testcase_20 AC 12 ms
5,376 KB
testcase_21 AC 40 ms
9,088 KB
testcase_22 AC 25 ms
6,528 KB
testcase_23 AC 6 ms
5,376 KB
testcase_24 AC 12 ms
5,376 KB
testcase_25 AC 11 ms
5,376 KB
testcase_26 AC 66 ms
12,800 KB
testcase_27 AC 71 ms
14,336 KB
testcase_28 AC 56 ms
13,824 KB
testcase_29 AC 64 ms
16,128 KB
testcase_30 AC 76 ms
17,024 KB
testcase_31 AC 74 ms
17,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local n = io.read("*n")
local edge = {}
for i = 1, n do
  edge[i] = {}
end
for i = 1, n - 1 do
  local a, b = io.read("*n", "*n")
  table.insert(edge[a], b)
  table.insert(edge[b], a)
end
local c = 0
for i = 1, n do
  if 3 <= #edge[i] then
    if c == 0 then
      c = i
    else
      print("No") os.exit()
    end
  end
end
if c == 0 then print("Yes") os.exit() end
local len = {}
for i = 1, n do
  len[i] = -1
end
len[c] = 0
local tasks = {c}
for i = 1, n do
  local src = tasks[i]
  for j = 1, #edge[src] do
    local dst = edge[src][j]
    if len[dst] < 0 then
      len[dst] = len[src] + 1
      table.insert(tasks, dst)
    end
  end
end
local z = 0
for i = 1, n do
  if 1 == #edge[i] then
    if z == 0 then
      z = len[i]
    elseif z ~= len[i] then
      print("No") os.exit()
    end
  end
end
print("Yes")
0