#P7654. [BalticOI 1996] THE FILLING OF BARRELS (Day 2)
[BalticOI 1996] THE FILLING OF BARRELS (Day 2)
Description
There are identical empty barrels on a horizontal plane. Each barrel has a capacity of 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:
- “P” (pour) pour a certain amount of liquid into a specified barrel. The operation is written as: “P ”, where is the barrel number, and is the amount of liquid to pour into that barrel (in units).
- “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 ”, where and are the numbers of the two barrels connected by the pipe with that valve. The two different descriptions “V ” and “V ” 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 and (the number of operations). The next 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 of the testdata, . and are integers, , . and are integers, , , . .
Scoring
The score for this problem follows the original BOI settings. Full score is .
Notes
This problem comes from Baltic Olympiad in Informatics 1996: Day 2: THE FILLING OF BARRELS.
Translated and organized by @求学的企鹅.
Translated by ChatGPT 5
京公网安备 11011102002149号