Hello codeforces,hope we all are doing well:)i have some doubts in some question which came in my coding test

1)Given a undirected tree,you are at the root node .some of the nodes have cake in them and you takes one secong to walk over one edge.find the minimum time to catch all the cakes and come back to the stating node(root node in which you were standing at time=0) (i thought it might be dfs but do not know how to come up with it)

constraints:N<=1e4;(no of nodes)

2)About modulo for large number: p=2^(100)-1 and q=2^(1000001)-1 how to find p*inverse(q),where inverse(q) is the inverse modulo of q with 10^9+7.I have no clue bec for smaller number we could do iterative thing