結果

問題 No.1103 Directed Length Sum
ユーザー yuruhiyayuruhiya
提出日時 2020-07-05 12:07:29
言語 Crystal
(1.11.2)
結果
RE  
実行時間 -
コード長 352 bytes
コンパイル時間 20,529 ms
コンパイル使用メモリ 254,244 KB
実行使用メモリ 110,068 KB
最終ジャッジ日時 2023-09-13 11:03:21
合計ジャッジ時間 26,608 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,408 KB
testcase_02 RE -
testcase_03 AC 377 ms
87,444 KB
testcase_04 AC 482 ms
55,392 KB
testcase_05 AC 911 ms
86,072 KB
testcase_06 AC 310 ms
38,784 KB
testcase_07 AC 58 ms
12,752 KB
testcase_08 AC 93 ms
18,912 KB
testcase_09 AC 37 ms
10,688 KB
testcase_10 AC 142 ms
23,484 KB
testcase_11 AC 534 ms
59,532 KB
testcase_12 AC 314 ms
39,180 KB
testcase_13 AC 144 ms
24,008 KB
testcase_14 AC 25 ms
8,412 KB
testcase_15 AC 231 ms
32,308 KB
testcase_16 AC 630 ms
65,908 KB
testcase_17 AC 654 ms
68,352 KB
testcase_18 AC 143 ms
23,604 KB
testcase_19 AC 550 ms
60,920 KB
testcase_20 AC 41 ms
11,612 KB
testcase_21 AC 84 ms
14,856 KB
testcase_22 AC 455 ms
51,252 KB
testcase_23 AC 245 ms
33,936 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
  g[v].each do |u|
    res += dfs(u, dist + 1, g)
  end
  res
end

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