Advertisement
Guest User

Untitled

a guest
Dec 12th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Main where
  2.  
  3. import qualified Data.IntMap as M
  4.  
  5. main ::  IO ()
  6. main = do size <- getLine
  7.           nodes <- getLine
  8.           let tree = map read . words $ nodes :: [Int]
  9.               m = M.fromList $ map (\x -> (x, 1 + fun1 (a M.! x))) tree
  10.               a = M.fromList $ zip [0 ..] tree
  11.               fun1 (-1) = 1
  12.               fun1 i = m M.! i
  13.           print $ maximum $ map fun1 tree
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement