結果

問題 No.1103 Directed Length Sum
ユーザー yuruhiyayuruhiya
提出日時 2020-07-05 12:09:19
言語 Crystal
(1.11.2)
結果
RE  
実行時間 -
コード長 359 bytes
コンパイル時間 17,275 ms
コンパイル使用メモリ 255,548 KB
実行使用メモリ 110,356 KB
最終ジャッジ日時 2023-09-13 11:04:31
合計ジャッジ時間 26,515 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,544 KB
testcase_02 RE -
testcase_03 AC 374 ms
87,536 KB
testcase_04 AC 497 ms
55,448 KB
testcase_05 AC 929 ms
86,064 KB
testcase_06 AC 285 ms
38,808 KB
testcase_07 AC 48 ms
12,756 KB
testcase_08 AC 81 ms
18,580 KB
testcase_09 AC 32 ms
10,656 KB
testcase_10 AC 122 ms
23,544 KB
testcase_11 AC 508 ms
59,644 KB
testcase_12 AC 285 ms
39,076 KB
testcase_13 AC 122 ms
24,040 KB
testcase_14 AC 24 ms
8,552 KB
testcase_15 AC 212 ms
32,288 KB
testcase_16 AC 586 ms
66,104 KB
testcase_17 AC 612 ms
68,520 KB
testcase_18 AC 118 ms
23,544 KB
testcase_19 AC 519 ms
60,940 KB
testcase_20 AC 38 ms
11,564 KB
testcase_21 AC 75 ms
14,776 KB
testcase_22 AC 407 ms
51,352 KB
testcase_23 AC 226 ms
34,072 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 = (1..dist).sum.to_i64
  g[v].each do |u|
    res += dfs(u, dist + 1, g)
  end
  res
end

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