P28443 [洛谷] Barracuda
提高
题目描述

Problem Background

The journey of the small square is not going smoothly.

Along the way, the small square has seen beautiful islands polluted, majestic volcanoes, and encountered many enemies.

Currently, the small square is dealing with a huge triangle.

Problem Description

The large triangle tells the small square about its past: it used to be a treasure hunter, but was corrupted by the Dark Lord, which led to its current predicament.

It also hopes that the small square will defeat the Dark Lord, but due to the extensive surveillance by the Dark Lord's informants, it must set obstacles for the small square to deceive those "informants."

The problem it presents to the small square is this: it has $n$ small triangles, each with a certain mass. It has conducted $n + 1$ weighings of these triangles, but due to issues with the balance scale (?), one of the weighing results is incorrect.

Now, the large triangle wants to know the number of the heaviest small triangle.

A set of input is valid if and only if it meets the following conditions:

There does not exist a pair of $i$, $j$ such that when we assume the $i$-th weighing data is incorrect, we can find a valid solution, and when we assume the $j$-th weighing data is incorrect, we can also find a valid solution.

A valid solution is defined as follows:

  1. There is only one heaviest triangle.
  2. There are no triangles with uncertain weights.
  3. All triangle weights are positive integers.

Input Format

The first line of input is a positive integer $n$, representing the number of small triangles.

The next $n + 1$ lines each follow this format:

First is a positive integer $m$, indicating the number of small triangles weighed this time.

Next are $m$ integers, representing the numbers of the weighed small triangles.

Finally, an integer $weight$, indicating the result of this weighing.

Output Format

If the input is valid, output the number of the heaviest small triangle; otherwise, output "illegal" (without quotes).

Sample Input and Output

Sample Input #1

2
1 1 2
2 1 2 5
2 1 2 1

Sample Output #1

2

Sample Input #2

2
1 1 2
2 1 2 4
2 1 2 5

Sample Output #2

2

Sample Input #3

2
1 1 2
2 1 2 6
2 1 2 5

Sample Output #3

illegal

Notes

Example 1:

If the result of the first weighing is incorrect, no correct solution can be derived.

If the result of the second weighing is incorrect, the weight of the second small triangle would be negative, which is obviously incorrect.

If the result of the third weighing is incorrect, we derive that the weight of the 1st small triangle is 2, and the weight of the 2nd small triangle is 3, making the 2nd small triangle the heaviest.

This problem uses bundled testing with three subtasks described as follows:

$subtask 0 - 30Pts$ Guarantees that the weights of the small triangles are <= 20 and $n <= 5$. In this subtask, you earn 10 points for each passed test case.

$subtask 1 - 30Pts$ Guarantees that the weights of the small triangles are <= 100 and $n <= 100$, with data generated randomly.

$subtask 2 - 40Pts$ Guarantees that the weights of the small triangles are <= 100 and $n <= 100$.

In the last two subtasks, you must pass all data to earn points.

For 100% of the data, $1 <= m <= n$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 1 1 2 2 1 2 5 2 1 2 1
样例输出
2