change maxtree to mintree using priority_queue