Under construction

Still being built. Things may change

Too Many Edges

Time limit15sMemory limit2048 MB

Summary
Given a DAG G' that contains up to 200 extra edges beyond the original DAG G, find the longest path in G by querying which edges belong to G within a limited query budget.
Level

Hard9 of 10

Topics
Graph, Dynamic programming, Topological sort
Solved
No attempts yet

Statement

This is an interactive problem. You have to use the flush operation right after printing each line. For example, you can use fflush(stdout) in C or C++, System.out.flush() in Java, flush(output) in Pascal, and sys.stdout.flush() in Python.

You are an ordinary employee of a data analysis department. Your colleagues made trouble again. They downloaded a large graph from a remote server and analyzed it. Then their program added new edges to the graph without making a backup. Now they want the longest path in the original graph. Downloading the graph again takes too long, so you must recover the answer.

The original graph on the remote server is a directed acyclic graph G=(V,E)G=(V,E). All edges have unit length. Your input is a modified graph G′=(V,E′)G'=(V,E'), where E⊆E′E\subseteq E' and G′G' is a directed acyclic graph.

Your program must output ℓ(G)\ell(G), the length of the longest path in GG. The length of a path is the number of edges in it.

To test whether an edge belongs to the original graph, your program can query the remote server. To query whether edge u→vu \to v belongs to GG, print ? u v. Flush the output after each query. The server responds with 1 if the edge is in GG and 0 otherwise.

When you know the answer, print ! ans, where ans=ℓ(G)ans = \ell(G). Flush the output and terminate the program normally.

Your program may make at most (∣E′∣−∣E∣+1)×(ℓ(G)+1)(|E'| - |E| + 1) \times (\ell(G) + 1) queries (not counting the answer line), although ∣E∣|E| and ℓ(G)\ell(G) are unknown to you.

Input

The first line contains two integers nn and mm (1≤n≤5⋅1041 \le n \le 5 \cdot 10^4; 1≤m≤1051 \le m \le 10^5): the number of vertices and edges of G′G'.

Each of the next mm lines contains two integers uu and vv (1≤u,v≤n1 \le u, v \le n) describing a directed edge u→vu \to v in G′G'. No edge appears more than once. It is guaranteed that 0≤∣E′∣−∣E∣≤2000 \le |E'| - |E| \le 200.

The following lines contain the responses to your queries, each 0 or 1. The ii-th of these lines responds to your ii-th query. After (∣E′∣−∣E∣+1)×(ℓ(G)+1)(|E'| - |E| + 1) \times (\ell(G) + 1) queries, the server stops responding. The server sends a response only after your program prints a query and flushes the output.

Output

Print each query as ? u v on its own line, with 1≤u,v≤n1 \le u, v \le n. Flush the output after every line. When you find the answer, print ! ans on its own line and terminate the program.

Examples1

  1. Example 1

    Input
    5 5
    1 2
    1 3
    2 5
    3 4
    4 5
    1
    1
    1
    0
    1
    
    Expected output
    ? 1 2
    ? 1 3
    ? 2 5
    ? 3 4
    ? 4 5
    ! 2