#P17548. [JAG 2026 Summer Camp #2] Longest Path on DAG
[JAG 2026 Summer Camp #2] Longest Path on DAG
Problem Description
This is an interactive problem.
You are given a positive integer and a sequence of length whose elements are all either or .
There is a directed bipartite graph with vertices numbered . Each vertex of is colored: vertex is white if and black if . Every directed edge in satisfies both of the following conditions:
- .
- Vertices and have different colors.
The judge has hidden, and you are not explicitly given any information about its edges. Instead, you may send the following two types of queries to the judge, at most queries in total:
in u V: Ask the judge about a black vertex and a set of zero or more white vertices. The judge answers whether there exists a vertex in such that the edge exists.out u V: Ask the judge about a black vertex and a set of zero or more white vertices. The judge answers whether there exists a vertex in such that the edge exists.
Output any one of the longest paths in .
Note that the hidden graph is fixed before the interaction and remains unchanged.
Interaction
First, an integer () is given from standard input. The next line contains integers , each of which is or , separated by spaces.
N
S_1 S_2 ... S_N
After reading the input, you may make at most in queries and out queries in total, as described below.
in query
First, choose a black vertex and a set of zero or more white vertices. Then, construct a string of length consisting only of 0s and 1s such that is 1 if and only if . Print the query to standard output in the following format:
in u T
The judge determines whether there exists a vertex in such that the edge exists. Let be if such a vertex exists and otherwise. The value is given from standard input in the following format:
r
out query
First, choose a black vertex and a set of zero or more white vertices. Then, construct a string of length consisting only of 0s and 1s such that is 1 if and only if . Print the query to standard output in the following format:
out u T
The judge determines whether there exists a vertex in such that the edge exists. Let be if such a vertex exists and otherwise. The value is given from standard input in the following format:
r
Once you have determined a longest path, let be the vertex numbers in the order in which they appear on the path, and print your answer to standard output in the following format:
! k v_1 v_2 ... v_k
Terminate your program immediately after outputting the answer.
Notes on Interactive Judging
If your output does not conform to the specified format, or if your program terminates without outputting an answer, the verdict is undefined. Terminate your program immediately after outputting the answer. Otherwise, the verdict is undefined.
Whenever you output something, end it with a newline and flush standard output.
If you make more than queries, the verdict is undefined. Note that outputting the answer does not count as a query.
5
1 0 0 1 0
1
1
0
1
out 1 01101
in 4 01100
in 4 01000
out 4 01001
! 4 1 3 4 5
Hint
In this sample interaction, the hidden graph has the edge set . This information is not given to the program.