Longest Trip
Time limit1sMemory limit1024 MB
Find a longest simple path in a hidden graph by asking whether any road exists between two disjoint sets of landmarks.
- Level
Hard8 of 10
- Topics
- Divide and conquer, Graph, Binary search
- Solved
- No attempts yet
Problem
There are landmarks at Ópusztaszer, numbered from to . Some pairs of landmarks are connected by roads, which run in both directions. Each pair of landmarks is connected by at most one road. The organizers do not know which landmarks are connected.
The density of the road network is at least if every three distinct landmarks have at least roads among them. In other words, for each triplet with , at least of the pairs , and are connected by a road.
The organizers know a positive integer such that the density of the road network is at least . The value of cannot be greater than .
The organizers can call the phone dispatcher to learn about road connections between certain landmarks. Each call takes two nonempty arrays of landmarks, and . The landmarks in must be pairwise distinct, the landmarks in must be pairwise distinct, and no landmark may appear in both arrays.
For each call, the dispatcher checks every pair , with and . If any pair and is connected by a road, the dispatcher returns true. Otherwise it returns false.
A trip of length is a sequence of distinct landmarks where and are connected by a road for each . A trip of length is a longest trip if no trip of length or more exists.
Your task is to find a longest trip at Ópusztaszer by making calls to the dispatcher.
Constraints
- The sum of over all calls to
longest_tripdoes not exceed in each test case.