Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ABC 026-C 高橋君の給料
n=gets.to_i
@g=Array.new(n){[]}
(n-1).times do |i|
b=gets.to_i
@g[b-1]<< i+1
end
def rec i
if @g[i].size()==0
1
else
s=[]
@g[i].each do |j|
s<< rec(j)
end
s.max+s.min+1
end
end
puts rec 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment