結果

問題 No.1103 Directed Length Sum
ユーザー yuruhiyayuruhiya
提出日時 2020-07-05 12:14:53
言語 Crystal
(1.11.2)
結果
AC  
実行時間 1,070 ms / 3,000 ms
コード長 347 bytes
コンパイル時間 18,605 ms
コンパイル使用メモリ 255,764 KB
実行使用メモリ 152,268 KB
最終ジャッジ日時 2023-09-13 11:05:58
合計ジャッジ時間 28,513 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,400 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 519 ms
152,268 KB
testcase_03 AC 384 ms
87,540 KB
testcase_04 AC 585 ms
55,416 KB
testcase_05 AC 1,070 ms
85,964 KB
testcase_06 AC 373 ms
38,736 KB
testcase_07 AC 70 ms
12,720 KB
testcase_08 AC 121 ms
17,520 KB
testcase_09 AC 36 ms
10,536 KB
testcase_10 AC 176 ms
23,748 KB
testcase_11 AC 645 ms
59,472 KB
testcase_12 AC 377 ms
39,104 KB
testcase_13 AC 176 ms
24,020 KB
testcase_14 AC 26 ms
8,416 KB
testcase_15 AC 291 ms
32,340 KB
testcase_16 AC 728 ms
66,100 KB
testcase_17 AC 768 ms
68,440 KB
testcase_18 AC 177 ms
23,436 KB
testcase_19 AC 662 ms
60,760 KB
testcase_20 AC 47 ms
11,476 KB
testcase_21 AC 105 ms
14,764 KB
testcase_22 AC 531 ms
51,220 KB
testcase_23 AC 300 ms
34,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**9 + 7

n = read_line.to_i
g = Array.new(n) { [] of Int32 }
flag = [false] * n
n.pred.times do
  a, b = read_line.split.map &.to_i.pred
  g[a] << b
  flag[b] = true
end

def dfs(v, dist, g)
  res = (1i64..dist.to_i64).sum
  g[v].each do |u|
    res += dfs(u, dist + 1, g)
  end
  res % MOD
end

puts dfs(flag.index(false).not_nil!, 0, g)
0