Add on a Tree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You…