Author: | A. Usmanov | Time limit: | 1 sec | |
Input / output: | interactive | Memory limit: | 256 Mb |
This is an interactive problem. Your program will interact with a jury program by sending and receiving particular messages.
Petya has N vertices. He wants to connect them with edges to form a tree. Recall that a tree is a connected graph of N vertices and N − 1 edges.
Petya has already written a program that connects vertices with edges, but a problem arose during startup: the antivirus started complaining about it because of too much activity. To reduce the activity of his program, he asks you to write a second program, which will connect vertices in turn with his program.
And to make sure that the antivirus is less suspicious, Petya wants each node in the final tree to have no more than three edges.
The first line of input contains one integer N, the number of vertices in the tree.
To add an edge, your program should print "+ Ai Bi
", where Ai, Bi — integers, the numbers of vertices to be connected by the edge.
The jury program will respond to your program with the line "ok
". If after this it is still possible to add edges, then the jury program will also output "+ Ai Bi
", where Ai, Bi — integers, the numbers of the vertices that are connected by an edge. It is guaranteed that the jury program adds edges according to all the described rules. After this, the turn again goes to your program.
When the tree has exactly N − 1 edges, your program should terminate.
If your program adds an unnecessary edge, it will receive "Wrong answer" verdict.
If your program makes incorrect query, it will receive "Presentation error" verdict.
If your program receives the string "error
" instead of "ok
" from the jury's program,
it must immediately terminate.
This is possible if your program violates the interaction protocol.
If your program does not terminate, the verdict may differ from those described above
(for example, it may be "Runtime error").
Every query must be a single line ending with single end-of-line (\n
).
Output buffers must be flushed after every line:
Language | C++ | Pascal | Java | Python |
Code | cout.flush() |
flush(output) |
System.out.flush() |
stdout.flush() |
3 ≤ N ≤ 1000
1 ≤ Ai, Bi ≤ N
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|