結果

問題 No.1103 Directed Length Sum
コンテスト
ユーザー yuruhiya
提出日時 2020-07-05 12:07:29
言語 Crystal
(1.19.1)
コンパイル:
crystal build -Donline_judge -o a.out --release --no-debug _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 352 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,672 ms
コンパイル使用メモリ 338,188 KB
実行使用メモリ 109,504 KB
最終ジャッジ日時 2026-03-21 06:21:54
合計ジャッジ時間 15,612 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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