Last active
March 26, 2017 05:37
-
-
Save ia7ck/f905e14937e91b8ea96c01ed23695930 to your computer and use it in GitHub Desktop.
ABC 026-C 高橋君の給料
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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