#P7654. [BalticOI 1996] THE FILLING OF BARRELS (Day 2)

[BalticOI 1996] THE FILLING OF BARRELS (Day 2)

Description

There are NN identical empty barrels on a horizontal plane. Each barrel has a capacity of 100100 units. Every pair of barrels is connected by a pipe. Each pipe connects to the bottoms of the two barrels and has its own valve, which can only be “open” or “closed”. Initially, all valves are closed. If a valve is open, then liquid from one of the connected barrels can quickly flow freely to the other barrel, making the amounts of liquid in these barrels equal (the principle of communicating vessels). If a valve is closed, liquid cannot pass through that pipe.

Two types of operations are allowed:

  1. “P” (pour) pour a certain amount of liquid into a specified barrel. The operation is written as: “P nn mm”, where nn is the barrel number, and mm is the amount of liquid to pour into that barrel (in units).
  2. “V” (valve) switch a specified valve to the opposite state (i.e., if it was open it becomes closed, and if it was closed it becomes open). The operation is written as: “V n1n_1 n2n_2”, where n1n_1 and n2n_2 are the numbers of the two barrels connected by the pipe with that valve. The two different descriptions “V n1n_1 n2n_2” and “V n2n_2 n1n_1” refer to the same valve.

Your goal is to execute the given sequence of operations. You must ignore the amount of liquid inside the pipes. If some pouring operation cannot be performed because of overflow, you must stop executing the sequence after producing the required output.

Input Format

The first line contains integers NN and KK (the number of operations). The next KK lines contain operation descriptions, one per line.

Output Format

Output either “OK” and the minimum and maximum amounts of liquid among all barrels at the end of the execution, or “OVERFLOW” and the operation where the overflow occurs. The amounts of liquid must be printed as real numbers with exactly two digits after the decimal point.

3 8
P 1 100
V 2 1
P 2 40
V 1 2
V 1 3
V 1 3
P 3 70
V 1 3 
OK 75.00 95.00 
3 8 
P 1 100
V 2 1
P 2 40
V 1 2
V 1 3
V 1 3
P 3 70
V 1 3 
OVERFLOW 7 

Hint

Constraints

For 100%100 \% of the testdata, 1<N1001 < N \le 100. nn and mm are integers, 0<nN0 < n \le N, 0<m10000 < m \le 1000. n1n_1 and n2n_2 are integers, 0<n1N0 < n_1 \le N, 0<n2N0 < n_2 \le N, n1n2n_1 \ne n_2. 0<K10000 < K \le 1000.

Scoring

The score for this problem follows the original BOI settings. Full score is 2525.

Notes

This problem comes from Baltic Olympiad in Informatics 1996: Day 2: THE FILLING OF BARRELS.
Translated and organized by @求学的企鹅.

Translated by ChatGPT 5