結果

問題 No.1103 Directed Length Sum
ユーザー yuruhiya
提出日時 2020-07-05 12:09:19
言語 Crystal
(1.14.0)
結果
RE  
実行時間 -
コード長 359 bytes
コンパイル時間 11,624 ms
コンパイル使用メモリ 296,932 KB
実行使用メモリ 97,048 KB
最終ジャッジ日時 2024-06-30 20:30:02
合計ジャッジ時間 21,625 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21 RE * 1
権限があれば一括ダウンロードができます

ソースコード

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