#K62292. Minimum Stops for Collecting Snacks

    ID: 31499 Type: Default 1000ms 256MiB

Minimum Stops for Collecting Snacks

Minimum Stops for Collecting Snacks

You are given n refreshment points, each offering a combination of three types of snacks: water, energy bars, and fruits. Each point is represented by three binary values: the first for water, the second for energy bars, and the third for fruits. A value of 1 indicates that the corresponding snack is available at that point, and 0 indicates it is not available.

Your task is to determine the minimum number of stops (i.e. refreshment points) you need to visit so that you collect all three types of snacks at least once. If it is impossible to collect all three, output -1.

The solution involves finding a subset of these refreshment points whose combined available snacks cover all three types. Formally, if we denote the snacks as \(\{water,\ energy\ bars,\ fruits\}\), you need to choose a subset \(S\) such that:

[ \bigcup_{i \in S} snacks_i = {water,\ energy\ bars,\ fruits}\n]

and the size of \(S\) is minimized.

inputFormat

The input is given via standard input (stdin). The first line contains an integer n representing the number of refreshment points. The following n lines each contain three space-separated integers. Each line represents a refreshment point where the three integers indicate the availability of water, energy bars, and fruits respectively (1 means available, 0 means not available).

outputFormat

Output via standard output (stdout) a single integer which is the minimum number of stops required to collect all three types of snacks. If it is not possible, output -1.

## sample
1
1 1 1
1

</p>