#GL0000401. Tìm cặp đỉnh có GCD đường đi lớn nhất (Maximum-GCD Path Pair)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tìm cặp đỉnh có GCD đường đi lớn nhất (Maximum-GCD Path Pair)
Maximum-GCD Path Pair
Source: Codeforces
Version: Phuoc Hung OJ Extended
Mode: interactive.
Problem Statement
The structure of an undirected tree with vertices is public, but the positive edge weights are hidden. For distinct vertices , define as the GCD of weights along their unique path.
Find two distinct vertices maximizing over all vertex pairs.
You may ask at most 12 queries of the form ? k v_1 ... v_k, where and the listed vertices are distinct. The judge returns the maximum over all pairs in the queried set. Finish by printing ! a b, which does not count as a query. Flush every question.
PHOJ hidden input
The test file contains followed by lines u v w. The interactor reveals only and all endpoint pairs u v, not the weights. The judge answers queries using the hidden edge weights.
Subtasks
- Subtask 1 (20 points): , , tree, at most 12 queries.
- Subtask 2 (30 points): , , tree, at most 12 queries.
- Subtask 3 (50 points): , , tree, at most 12 queries.
Example interaction
Suppose the hidden weighted edges are .
Judge: 4
Judge: 1 2
Judge: 1 4
Judge: 2 3
Player: ? 4 1 2 3 4
Judge: 15
Player: ? 2 1 2
Judge: 6
Player: ? 3 1 2 3
Judge: 15
Player: ! 2 3
Explanation: The single edge (2,3) gives path GCD 15. A multi-edge path cannot have GCD greater than the maximum individual edge weight, which is 15. Thus this pair is optimal.