Orange Boy Can You Solve It Out? Ep.6
思考题 for no one
Tour
You are given a tree of N nodes. Given another integer array A of length M.
Little CMJ chooses M sequences of nodes. The i-th of them is X_1,X_2...X_{A_i} and he chooses them so that for each 1\leq i\leq A_i-1,there's an edge from X_i to X_{i+1}, and X_1=1. Then he set all the nodes in the sequences "visited"
Can all the nodes be visited after choosing the M sequences?
Example
Example 1
Tree={[1,2],[2,3],[2,4],[4,7],[1,5],[1,6]}
M={3,4,2,2}
Answer:
YES
Explain:
{1,2,3} {1,2,4,7} {1,5} {1,6} is chosen
Example 2
Tree={[1,2],[2,3],[2,4],[4,7],[1,5],[1,6]}
M={6,2,2}
Answer:
YES
Explain:
{1,2,3,2,4,7} {1,5} {1,6} is chosen
Example 3
Tree={[1,2],[2,3],[2,4],[4,7],[1,5],[1,6]}
M={9}
Answer:
NO
Explain:
if M={10}, then possible: {1,5,1,6,1,2,3,2,4,7}
版权声明:
作者:XGN
链接:https://blog.hellholestudios.top/archives/143
来源:Hell Hole Studios Blog
文章版权归作者所有,未经允许请勿转载。
共有 0 条评论