Language: C++

n = gets.to_i

class Node
  attr_accessor :id, :parent, :left, :right, :sibling, :degree, :depth, :height, :node_type
  def initialize(i)
    @id = i
    @parent = -1
    @left = -1
    @right = -1
    @depth = 0
    @height = 0
    @sibling = -1
    @degree = -1
  end
end

nodes = {}
# 大きさが分かるので初期化しておく
n.times do |i|
  nodes[i] = Node.new(i)
end
# 階層
levels = []

def heightrec(par, nodes)
  l, r = 0, 0
  if nodes[par].left >= 0
    tmp_left = nodes[par].left
    l = heightrec(tmp_left, nodes) + 1
  end
  if nodes[par].right >= 0
    tmp_right = nodes[par].right
    r = heightrec(tmp_right, nodes) + 1
  end
  nodes[par].height = [r, l].max
end

def depthrec(par, nodes)
  left_child = nodes[par].left
  if left_child >= 0
    nodes[left_child].depth = nodes[par].depth + 1
    depthrec(left_child, nodes)
  end
  right_child = nodes[par].right
  if right_child >= 0
    nodes[right_child].depth = nodes[par].depth + 1
    depthrec(right_child, nodes)
  end
end

n.times do |i|
  data = gets.chomp.split.map(&:to_i)
  my_id = data[0]
  child_l = data[1]
  child_r = data[2]
  # 子データをセット
  nodes[my_id].left = child_l
  nodes[my_id].right = child_r
  # 子に親と兄弟データをセット
  if child_l >= 0
    nodes[child_l].parent = my_id
    if child_r >= 0
      nodes[child_l].sibling = child_r
    end
  end
  if child_r >= 0
    nodes[child_r].parent = my_id
    if child_l >= 0
      nodes[child_r].sibling = child_l
    end
  end
  # 子の数をセット
  nodes[my_id].degree = [child_l, child_r].select{|c|c!=-1}.size
  # 深さ更新
  depthrec(my_id, nodes)
end

# 高さ計算とタイプ
# root、internal node、leaf 
nodes.each do |k, node|
  heightrec(k, nodes)
  if node.parent == -1
    node.node_type = "root"
  elsif node.degree.zero? 
    node.node_type = "leaf"
  else
    node.node_type = "internal node"
  end
end

# 出力
# node id: parent = p , sibling = s , degree = deg, depth = dep, height = h, type
nodes.each do |k, node|
  puts "node #{node.id}: parent = #{node.parent}, sibling = #{node.sibling}, degree = #{node.degree}, depth = #{node.depth}, height = #{node.height}, #{node.node_type}"
end


Compiler output:
a.cc:6:5: error: stray '@' in program
    6 |     @id = i
      |     ^
a.cc:7:5: error: stray '@' in program
    7 |     @parent = -1
      |     ^
a.cc:8:5: error: stray '@' in program
    8 |     @left = -1
      |     ^
a.cc:9:5: error: stray '@' in program
    9 |     @right = -1
      |     ^
a.cc:10:5: error: stray '@' in program
   10 |     @depth = 0
      |     ^
a.cc:11:5: error: stray '@' in program
   11 |     @height = 0
      |     ^
a.cc:12:5: error: stray '@' in program
   12 |     @sibling = -1
      |     ^
a.cc:13:5: error: stray '@' in program
   13 |     @degree = -1
      |     ^
a.cc:18:3: error: invalid preprocessing directive #\U00005927\U0000304d\U00003055\U0000304c\U00005206\U0000304b\U0000308b\U0000306e\U00003067\U0000521d\U0000671f\U00005316\U00003057\U00003066\U0000304a\U0000304f
   18 | # 大きさが分かるので初期化しておく
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:22:3: error: invalid preprocessing directive #\U0000968e\U00005c64
   22 | # 階層
      |   ^~~~
a.cc:56:5: error: invalid preprocessing directive #\U00005b50\U000030c7\U000030fc\U000030bf\U00003092\U000030bb\U000030c3\U000030c8
   56 |   # 子データをセット
      |     ^~~~~~~~~~~~~~~~
a.cc:59:5: error: invalid preprocessing directive #\U00005b50\U0000306b\U000089aa\U00003068\U00005144\U00005f1f\U000030c7\U000030fc\U000030bf\U00003092\U000030bb\U000030c3\U000030c8
   59 |   # 子に親と兄弟データをセット
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:72:5: error: invalid preprocessing directive #\U00005b50\U0000306e\U00006570\U00003092\U000030bb\U000030c3\U000030c8
   72 |   # 子の数をセット
      |     ^~~~~~~~~~~~~~
a.cc:74:5: error: invalid preprocessing directive #\U00006df1\U00003055\U000066f4\U000065b0
   74 |   # 深さ更新
      |     ^~~~~~~~
a.cc:78:3: error: invalid preprocessing directive #\U00009ad8\U00003055\U00008a08\U00007b97\U00003068\U000030bf\U000030a4\U000030d7
   78 | # 高さ計算とタイプ
      |   ^~~~~~~~~~~~~~~~
a.cc:79:3: error: extended character 、 is not valid in an identifier
   79 | # root、internal node、leaf
      |   ^
a.cc:79:3: error: invalid preprocessing directive #root\U00003001internal
   79 | # root、internal node、leaf
      |   ^~~~~~~~~~~~~~
a.cc:79:18: error: extended character 、 is not valid in an identifier
   79 | # root、internal node、leaf
      |                  ^
a.cc:91:3: error: invalid preprocessing directive #\U000051fa\U0000529b
   91 | # 出力
      |   ^~~~
a.cc:92:3: error: invalid preprocessing directive #node
   92 | # node id: parent = p , sibling = s , degree = deg, depth = dep, height = h, type
      |   ^~~~
a.cc:1:1: error: 'n' does not name a type
    1 | n = gets.to_i
      | ^
a.cc:19:1: error: 'n' does not name a type
   19 | n.times do |i|
      | ^
a.cc:73:60: error: expected unqualified-id before '.' token
   73 |   nodes[my_id].degree = [child_l, child_r].select{|c|c!=-1}.size
      |                                                            ^