結果

問題 No.827 総神童数
ユーザー 👑 obakyanobakyan
提出日時 2020-05-04 21:04:49
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 5,236 KB
実行使用メモリ 36,060 KB
最終ジャッジ日時 2023-09-07 04:59:55
合計ジャッジ時間 11,338 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 346 ms
33,112 KB
testcase_10 AC 105 ms
15,016 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 40 ms
7,040 KB
testcase_13 AC 272 ms
29,564 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 94 ms
11,396 KB
testcase_16 AC 270 ms
29,584 KB
testcase_17 AC 323 ms
32,360 KB
testcase_18 AC 129 ms
16,300 KB
testcase_19 AC 411 ms
36,060 KB
testcase_20 AC 296 ms
30,512 KB
testcase_21 AC 209 ms
20,044 KB
testcase_22 AC 330 ms
31,900 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 359 ms
33,664 KB
testcase_25 AC 275 ms
29,112 KB
testcase_26 AC 367 ms
33,800 KB
testcase_27 AC 227 ms
21,356 KB
testcase_28 AC 228 ms
21,072 KB
testcase_29 AC 175 ms
18,640 KB
testcase_30 AC 43 ms
7,156 KB
testcase_31 AC 137 ms
16,516 KB
testcase_32 AC 128 ms
16,072 KB
testcase_33 AC 399 ms
35,444 KB
testcase_34 AC 370 ms
33,672 KB
testcase_35 AC 136 ms
16,460 KB
testcase_36 AC 201 ms
19,756 KB
testcase_37 AC 261 ms
22,996 KB
testcase_38 AC 389 ms
35,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mod = 1000000007
local mfl = math.floor

local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end
local n = io.read("*n")
local edge = {}
local len = {}
for i = 1, n do
  edge[i] = {}
  len[i] = -1
end
for i = 1, n - 1 do
  local u, v = io.read("*n", "*n")
  edge[u][v], edge[v][u] = true, true
end
len[1] = 0
local tasks = {1}
for i = 1, n do
  local src = tasks[i]
  for dst, _u in pairs(edge[src]) do
    if len[dst] < 0 then
      len[dst] = len[src] + 1
      table.insert(tasks, dst)
    end
  end
end

local fact = {1}
local invs = {1}
local invfact = {1}
for i = 2, n do
  fact[i] = bmul(fact[i - 1], i)
  invs[i] = bmul(mfl(mod / i), mod - invs[mod % i])
  invfact[i] = bmul(invfact[i - 1], invs[i])
end

local ret = 0
for i = 1, n do
  ret = badd(ret, invs[1 + len[i]])
end
ret = bmul(ret, fact[n])
print(ret)
0