結果

問題 No.827 総神童数
ユーザー 👑 obakyanobakyan
提出日時 2020-05-04 21:05:59
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 381 ms / 2,000 ms
コード長 920 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 5,336 KB
実行使用メモリ 31,680 KB
最終ジャッジ日時 2023-09-07 05:02:31
合計ジャッジ時間 8,343 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 325 ms
28,800 KB
testcase_10 AC 95 ms
12,812 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 36 ms
6,228 KB
testcase_13 AC 251 ms
25,148 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 86 ms
10,084 KB
testcase_16 AC 256 ms
25,212 KB
testcase_17 AC 295 ms
28,044 KB
testcase_18 AC 112 ms
14,032 KB
testcase_19 AC 381 ms
31,680 KB
testcase_20 AC 266 ms
26,040 KB
testcase_21 AC 182 ms
17,828 KB
testcase_22 AC 298 ms
27,400 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 339 ms
29,308 KB
testcase_25 AC 244 ms
24,768 KB
testcase_26 AC 337 ms
29,452 KB
testcase_27 AC 216 ms
19,128 KB
testcase_28 AC 201 ms
18,756 KB
testcase_29 AC 157 ms
16,400 KB
testcase_30 AC 39 ms
6,504 KB
testcase_31 AC 119 ms
14,304 KB
testcase_32 AC 111 ms
13,844 KB
testcase_33 AC 374 ms
31,056 KB
testcase_34 AC 345 ms
29,260 KB
testcase_35 AC 118 ms
14,216 KB
testcase_36 AC 185 ms
17,552 KB
testcase_37 AC 246 ms
20,640 KB
testcase_38 AC 366 ms
30,748 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 f = 1
local invs = {1}
for i = 2, n do
  f = bmul(f, i)
  invs[i] = bmul(mfl(mod / i), mod - invs[mod % i])
end

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