Coin Collecting
Time limit2sMemory limit128 MB
Choose one envelope from each pair over r rounds so that no non-empty subset of chosen envelopes forms a country-parity cycle (linear independence over GF(2)), maximizing 2 times the number of chosen envelopes.
- Level
Hard8 of 10
- Topics
- Union-find, Greedy, Graph
- Solved
- No attempts yet
Problem
As a member of the Association of Coin Minters (ACM), you are fascinated by all kinds of coins, and one of your hobbies is collecting national currency from different countries. Your friend, also an avid coin collector, has her heart set on some of your precious coins and proposes a game that lets the winner acquire the loser's collection (or part of it).
She begins by preparing two envelopes, each enclosing two coins that come from different countries. Then she asks you to choose one of the two envelopes. You can see their contents before making your choice, and you may also decline the offer and take neither. This process is repeated a total of times. As the game progresses, you are also allowed to change your mind about your previous picks if you think you can do better. Eventually, your friend examines the envelopes in your final selection, and from among them she picks a few envelopes herself. If her selection is non-empty and includes an even number of coins from every country (possibly zero), she wins, and you must hand over your entire coin collection to her, making years of painstaking effort go to waste and forcing you to start afresh. But if you win, you get to keep the coins from all the envelopes you picked.
Despite the risks involved, the prospect of enlarging your collection is so appealing that you decide to take the challenge. You'd better make sure you win as many coins as possible.
Input
The first line of each test case is the number of rounds (); a line with indicates the end of the input. The next lines each contain four non-negative integers (), meaning that your friend puts coins from countries labelled and inside one envelope, and and inside the other. A blank line separates test cases.
Output
Print a line per test case containing the largest number of coins you are guaranteed.