結果

問題 No.1103 Directed Length Sum
ユーザー yuruhiyayuruhiya
提出日時 2020-07-05 12:10:21
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 362 bytes
コンパイル時間 18,815 ms
コンパイル使用メモリ 254,672 KB
実行使用メモリ 152,408 KB
最終ジャッジ日時 2023-09-13 11:02:14
合計ジャッジ時間 28,700 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,392 KB
testcase_02 WA -
testcase_03 AC 375 ms
87,640 KB
testcase_04 AC 498 ms
55,376 KB
testcase_05 AC 936 ms
85,948 KB
testcase_06 AC 299 ms
38,864 KB
testcase_07 AC 50 ms
12,820 KB
testcase_08 AC 80 ms
17,540 KB
testcase_09 AC 31 ms
10,692 KB
testcase_10 AC 127 ms
23,608 KB
testcase_11 AC 539 ms
59,656 KB
testcase_12 AC 296 ms
39,136 KB
testcase_13 AC 132 ms
24,096 KB
testcase_14 AC 24 ms
8,480 KB
testcase_15 AC 229 ms
32,332 KB
testcase_16 AC 629 ms
66,020 KB
testcase_17 AC 634 ms
68,620 KB
testcase_18 AC 151 ms
23,544 KB
testcase_19 AC 546 ms
60,976 KB
testcase_20 AC 38 ms
11,560 KB
testcase_21 AC 80 ms
14,984 KB
testcase_22 AC 439 ms
51,164 KB
testcase_23 AC 246 ms
34,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 : Int32, dist : Int32, g : Array(Array(Int32)))
  res = (1i64..dist.to_i64).sum
  g[v].each do |u|
    res += dfs(u, dist + 1, g)
  end
  res
end

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