You had a directed graph with
In one question to Siesta, you may ask about two sets of nodes
Your task is to change the orientation of some subset of the edges in the graph such that the resulting graph is acyclic. Can you solve this problem?
Interaction
This is an interactive problem. The first line contains
The next
You will then begin interaction with Siesta. To ask her a question, you should print
Line 1: ?
, followed by a space, followed by
Line 2:
Line 3:
Furthermore,
In response, you should read in one line from Siesta. This line will contain
If you believe you have a solution to the problem, you may output !
, followed by a space, followed by a binary string of length 1
if the 0
otherwise. You must terminate your program immediately after performing this operation.
If at any point your output is ill-formatted, you attempt an invalid question, or the sum of -1
. At this point your program should exit in order to receive a Wrong Answer
verdict.
Please note that you may need to flush stdout
after each operation, or interaction may halt. In C++, this can be done with fflush(stdout)
or cout << flush
(depending on whether you use printf
or cout
). In Java, this can be done with System.out.flush()
. In Python, you can use sys.stdout.flush()
.
Sample Interaction
>>>
denotes your output. Do not print this out.
4 5
4 1
4 2
2 1
2 3
4 3
>>> ? 2 1
>>> 1 3
>>> 4
2 1 5
>>> ? 1 1
>>> 3
>>> 2
0
>>> ? 4 4
>>> 1 3 2 4
>>> 2 3 4 1
5 3 4 1 5 2
>>> ! 00101
Sample Explanation
The initial graph is as follows (note that you cannot directly infer the orientations of the edges from the initial input):
After changing the orientation of the
This interaction would receive an Accepted
verdict, since the graph is indeed acyclic after changing the specified orientations, and the sum of
Comments