Skip to content

Problem 6: Decorate Christmas Tree II (0 pts)

Problem

This time, Isla bought 3 super big Christmas trees, which all have more than 30000 nodes! Can you still work out in less than 5 seconds?

这一次,Isla 买了 3 棵超级大的圣诞树,每棵都有超过 30000 个节点!你能在不到 5 秒内完成吗?

Hints

Hint1: You should scan every node only constant times.

Hint2: You can set up new attribute of Tree instance in your solution to memorize something! It doesn't violate abstraction barrier.

  • 你应该只扫描每个节点常数次。

  • 你可以在你的解决方案中为 Tree 实例设置新属性来记忆某些东西!这不会违反抽象屏障。