Too Many Edges
시간 제한15초메모리 제한2048 MB
원래의 DAG G에 최대 200개의 간선이 추가된 G'이 주어졌을 때, 간선 존재 질의를 (추가 간선 수+1)*(정답+1)번 이내로 사용해 G의 최장 경로 길이를 구한다.
문제
This is an interactive problem. You have to use the flush operation right after printing each line. For example, you can use the function fflush(stdout) for C or C++, System.out.flush() for Java, flush(output) for Pascal, and sys.stdout.flush() for Python.
You are an ordinary employee of a data analysis department. However, it seems that your colleagues are geniuses at making trouble. Just now they made some trouble again.
They downloaded a large graph from the remote server and wrote a program to analyze the graph. They nearly finished the analysis and thought the graph should be no longer useful. So they let their program add some new edges to the graph without any backups. But then they changed their mind and want to compute the longest path in the original graph. Downloading the graph again costs too much time. Now it is your time to save the day.
The original graph on the remote server is a directed acyclic graph . All edges are unit length. The input of your program is the modified version . It is guaranteed that , and is a directed acyclic graph.
Your program should output , the length of the longest path in . The length of a path equals the number of edges in the path.
To test whether an edge belongs to the original graph, your program can make queries to the remote server. To query the existence of edge , output "? ". Flush the output stream after printing each query. The remote server will respond 1 if edge belongs to the original graph, and 0 otherwise.
After your program gets the answer, print "! ", where , and terminate your program normally immediately after flushing the output stream.
Your program is allowed to make no more than queries (not including printing the answer) to the remote server, although and are unknown to you.
입력
Use standard input to read the responses to the queries.
The first line contains two integers and (; ): the number of vertices and edges of graph .
Each of the next lines contains two integers and () specifying a directed edge in graph . No edge appears more than once.
It is guaranteed that .
The following lines will contain responses to your queries. Each response is either "0" or "1". The -th of these lines is a response to your -th query.
After answering queries, the remote server no longer responds.
The testing system will allow you to read the response to a query only after your program prints the query and performs the flush operation.
출력
To make the queries, your program must use standard output.
Your program must print the queries in the form of "? ", one query per line. Do not forget to end the line after each query. Your program must guarantee that . After printing each line your program must perform the flush operation.
The response to the query will be given in the standard input after you flush the output. In case your program finds the answer, print a line "! ", where , and terminate your program.