#GL0000398. Phủ cây bằng ít đường đi nhất (Minimum Good Vertical Path Cover)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phủ cây bằng ít đường đi nhất (Minimum Good Vertical Path Cover)
Minimum Good Vertical Path Cover
Source: Codeforces
Version: Phuoc Hung OJ Extended
Mode: streaming interactive problem.
Problem Statement
A rooted tree has vertices, root 1, and a value on each vertex. Every parent index is smaller than each of its child indices.
A vertical path follows parent-to-child edges without branching. It is good if the GCD of all values on this path is greater than 1. Let be the minimum number of pairwise vertex-disjoint good vertical paths that cover all nodes in the subtree rooted at .
You must output in this order.
Interaction
First, read . For each , the judge sends a_u k c_1 ... c_k, where is the number of children, and each is a direct child of . Immediately output and flush. The judge sends the next vertex's information only after validating your current answer. All outputs must be correct.
Each PHOJ .in file stores one complete hidden tree. The interactor streams the vertex records one at a time; contestants must never read the hidden file directly. Unlike the original multi-case statement, one test case is used per PHOJ file.
Subtasks
- Subtask 1 (20 points): , , valid rooted tree with increasing indices.
- Subtask 2 (30 points): , , valid rooted tree with increasing indices.
- Subtask 3 (50 points): , , valid rooted tree with increasing indices.
Example interaction
Judge: 3
Judge: 6 0
Player: 1
Judge: 10 0
Player: 1
Judge: 15 2 2 3
Player: 2
Explanation: Nodes 2 and 3 individually require one path. In the subtree of node 1, paths (GCD 5) and (GCD 6) cover all nodes. One vertical path cannot cover both children of node 1, so the optimal number is 2.