All about problems in Volume 114. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
Oh, no wonder I couldn't find any faster algorithm. I thought of a bruteforce O(n*2^n) algorithm long time ago, but thought that the time limit is too tight for it. Now I see that I can use bitmask to make it O(2^n), which should be fast enough.
I don't quite understand what you mean by this, can you elaborate more please?We choose some leaves and make sure every node could reach at least one of them.
(and choose some roots to make sure every node could be reached from them)