Under construction

Still being built. Things may change

Longest Trip

Time limit1sMemory limit1024 MB

Summary
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 NN landmarks at Ópusztaszer, numbered from 00 to N−1N-1. 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 δ\delta if every three distinct landmarks have at least δ\delta roads among them. In other words, for each triplet (u,v,w)(u, v, w) with 0≤u<v<w<N0 \le u < v < w < N, at least δ\delta of the pairs (u,v)(u,v), (v,w)(v,w) and (u,w)(u,w) are connected by a road.

The organizers know a positive integer DD such that the density of the road network is at least DD. The value of DD cannot be greater than 33.

The organizers can call the phone dispatcher to learn about road connections between certain landmarks. Each call takes two nonempty arrays of landmarks, A[0],…,A[P−1]A[0], \ldots, A[P-1] and B[0],…,B[R−1]B[0], \ldots, B[R-1]. The landmarks in AA must be pairwise distinct, the landmarks in BB must be pairwise distinct, and no landmark may appear in both arrays.

For each call, the dispatcher checks every pair ii, jj with 0≤i<P0 \le i < P and 0≤j<R0 \le j < R. If any pair A[i]A[i] and B[j]B[j] is connected by a road, the dispatcher returns true. Otherwise it returns false.

A trip of length ll is a sequence of distinct landmarks t[0],t[1],…,t[l−1]t[0], t[1], \ldots, t[l-1] where t[i]t[i] and t[i+1]t[i+1] are connected by a road for each 0≤i≤l−20 \le i \le l-2. A trip of length ll is a longest trip if no trip of length l+1l+1 or more exists.

Your task is to find a longest trip at Ópusztaszer by making calls to the dispatcher.

Constraints

  • 3≤N≤2563 \le N \le 256
  • The sum of NN over all calls to longest_trip does not exceed 1 0241\,024 in each test case.
  • 1≤D≤31 \le D \le 3

Examples1

  1. Example 1

    Input
    3 3
    011
    101
    110
    
    Expected output
    3
    0 1 2