#P5473. Exploring the Underground Palace
Exploring the Underground Palace
Exploring the Underground Palace
I Jun, after his shop failed, ventured into an underground palace discovered in a vast desert. The palace is modeled as an undirected simple graph consisting of (N) caves and (M) bidirectional passages connecting these caves. The caves are numbered from (0) to (N-1). Initially, the state of each cave's light (on/off) is off. A mysterious machine allows I Jun to perform four operations:
- Given an index (x), toggle the light in cave (x) and in every cave directly connected to (x).
- Given an index (x), query the current state of the light in cave (x) (0 for off, 1 for on).
- Given two indices (x, y), record that there is a passage connecting cave (x) and cave (y). (It is guaranteed (0 \le x, y < N) and (x \neq y)).
- Given an index (x), check if all passages connected to cave (x) have been recorded.
The number of times each operation can be invoked is limited to (L_m), (L_q), (M), and (L_c) respectively. The graph is fixed before any interaction begins. Your task is to correctly discover all (M) passages using the machine by implementing the function below.
For C/C++ contestants, implement:
void explore(int N, int M);
For Pascal contestants, implement:
procedure _explore(N, M : longint);
You can interact with the machine using the following functions:
- modify(x): Toggles the light in cave (x) and its adjacent caves.
- query(x): Returns the state (0/1) of cave (x)'s light.
- report(x, y): Record a passage between caves (x) and (y).
- check(x): Returns 1 if all passages connected to cave (x) have been recorded, otherwise 0.
In this sample solution, we assume that the entire graph information (i.e. the list of passages) is provided in the input after the parameters. Then, the function simply reports all (M) passages. In a real interactive environment, you would normally discover the passages using the machine operations.
inputFormat
The input is read from standard input. The first line contains three integers (L_m), (L_q), (L_c) representing the limits for operations. The second line contains two integers (N) and (M) denoting the number of caves and passages. The following (M) lines each contain two integers (x) and (y) indicating a passage between cave (x) and cave (y).
outputFormat
The program should interact with the provided functions and ultimately call report(x,y) for each passage. In this sample solution, the output is the list of passages printed to standard output, one passage per line in the format: 'x y'.
sample
10 10 10
3 2
0 1
1 2
0 1
1 2
</p>