結果

問題 No.1098 LCAs
ユーザー yuruhiyayuruhiya
提出日時 2020-07-01 16:57:26
言語 Crystal
(1.11.2)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 554 bytes
コンパイル時間 17,934 ms
コンパイル使用メモリ 255,528 KB
実行使用メモリ 44,040 KB
最終ジャッジ日時 2023-09-13 10:57:37
合計ジャッジ時間 22,535 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,476 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,412 KB
testcase_03 AC 2 ms
4,400 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,408 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,520 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,424 KB
testcase_11 AC 3 ms
4,412 KB
testcase_12 AC 3 ms
4,448 KB
testcase_13 AC 3 ms
4,804 KB
testcase_14 AC 3 ms
4,776 KB
testcase_15 AC 3 ms
4,720 KB
testcase_16 AC 3 ms
4,756 KB
testcase_17 AC 3 ms
4,740 KB
testcase_18 AC 179 ms
32,444 KB
testcase_19 AC 178 ms
32,436 KB
testcase_20 AC 184 ms
32,792 KB
testcase_21 AC 184 ms
32,580 KB
testcase_22 AC 185 ms
32,496 KB
testcase_23 AC 135 ms
37,080 KB
testcase_24 AC 130 ms
38,064 KB
testcase_25 AC 128 ms
38,040 KB
testcase_26 AC 133 ms
39,272 KB
testcase_27 AC 135 ms
39,140 KB
testcase_28 AC 213 ms
42,188 KB
testcase_29 AC 207 ms
44,040 KB
testcase_30 AC 239 ms
42,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Solve
  def initialize
    @n = Int32.new read_line.to_i
    @g = Array(Array(Int32)).new(@n) { [] of Int32 }
    @n.pred.times do
      v, w = read_line.split.map &.to_i.pred
      @g[v] << w
      @g[w] << v
		end
		
    @ans = Array(Int64).new(@n, 0i64)
    dfs(0, -1)
    puts @ans.join('\n')
  end

  def dfs(v : Int32, par : Int32)
    child, bottom = 1i64, 0i64
    @g[v].select { |i| par != i }.each { |u|
      r = dfs(u, v)
      child += r
      bottom += r**2
    }
    @ans[v] = child**2 - bottom
    return child
  end
end

Solve.new
0