Skip to content

Instantly share code, notes, and snippets.

@ia7ck
Last active March 26, 2017 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ia7ck/f905e14937e91b8ea96c01ed23695930 to your computer and use it in GitHub Desktop.
Save ia7ck/f905e14937e91b8ea96c01ed23695930 to your computer and use it in GitHub Desktop.
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