[Solution] Railway System Codeforces Solution | Codeforces Problem Solution 2022
This is an interactive problem.
Under the direct supervision of Kanako and the Moriya Shrine, the railway system of Gensokyo is finally finished. GSKR (Gensokyo Railways) consists of stations with bidirectional tracks connecting them. The -th track has length (). Due to budget limits, the railway system may not be connected, though there may be more than one track between two stations.
The value of a railway system is defined as the total length of its all tracks. The maximum (or minimum) capacity of a railway system is defined as the maximum (or minimum) value among all of the currently functional system's full spanning forest.
In brief, full spanning forest of a graph is a spanning forest with the same connectivity as the given graph.
Kanako has a simulator only able to process no more than queries. The input of the simulator is a string of length , consisting of characters 0 and/or 1. The simulator will assume the -th track functional if 1. The device will then tell Kanako the maximum capacity of the system in the simulated state.
Kanako wants to know the the minimum capacity of the system with all tracks functional with the help of the simulator.
The structure of the railway system is fixed in advance. In other words,
the interactor is not adaptive.
The first and only line of input contains two integers (, ) — the number of stations and tracks.
Begin the interaction by reading .
To make a query, print "? " (without quotes, is a string of length , consisting of characters 0 and/or 1). Then you should read our response from standard input — the maximum capacity of the system in the simulated state.
If your program has made an invalid query or has run out of tries, the interactor will terminate immediately and your program will get a verdict Wrong answer.
To give the final answer, print "! " (without the quotes, is the minimum capacity of the system with all tracks functional). Note that giving this answer is not counted towards the limit of queries.
After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.
Hacks
The first line of input must contain two integers (, ) — the number of stations and tracks.
The next lines of input must contain exactly space-separated integers , , (, , ) — the endpoints and the length of the -th track.
No comments:
Post a Comment