AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

FPC24-023.European Election

Easy · 5 s · 256 MB

  • icpc
  • fpc
  • 2024

The European presidential election of 2042 are coming up soon. The First Presidential Committee has devised the most objective and representative election method. Every candidate is individually compared to every other candidate. The winner of the election is going to be the one candidate who is preferred over all other candidates.

To facilitate this, on their ballot, each voter lists candidates in order of preference. From those rankings, the head-to-head preferences of each voter are inferred. Not all candidates have to be ranked by every voter – omitted candidates are considered to all be ranked last by the voter (with no preference between them). A candidate is better than another candidate if more people prefer that candidate over the other one. If a candidate is better than every other candidate, they win the election.

Consider the second sample input, where there are seven voters and three candidates. In the head-to-head battle between candidates 111 and 222, four voters prefer candidate 111 and two voters prefer candidate 222 (one voter is indifferent about both), so candidate 111 wins that head-to-head match-up. Between candidates 111 and 333, four people prefer candidate 111, and three people prefer candidate 333, thus candidate 111 is better. Therefore, candidate 111 wins the election.

In case no candidate wins against all other candidates, then the results of the election are inconclusive – there is no winner. If, in a head-to-head battle, two candidates have the same number of preferences, then neither of them is considered better than the other. Thus, neither of them would be able to win the election.

Given the contents of each ballot, determine whether the election has a conclusive winner, and if so, who that winner is.

Giriş formatı

The input consists of:

• One line with integers nnn and kkk (1≤n≤20001 \leq n \leq 20001≤n≤2000, 1≤k≤2001 \leq k \leq 2001≤k≤200), denoting the number of ballots cast and the number of candidates.

• nnn lines, one for each ballot.

Each line starts with an integer vvv (0≤v≤2000 \leq v \leq 2000≤v≤200), the number of preferences on this ballot.

The remainder of this line has vvv integers ppp (1≤p≤k1 \leq p \leq k1≤p≤k), denoting the preferences of this voter – the first integer is the number of the voter's first preference candidate, the second integer is their second preference, and so on.

All the candidates that are unranked (i.e. not mentioned in the ballot) are considered to be all ranked last (i.e. tied with each other).

Çıxış formatı

If the election has a conclusive winner, output the number of the candidate who wins the election. Otherwise, output “impossible”.

Qeyd

Source: Freshmen Programming Contest 2024 · Author: Veselin Mitev · License: CC BY-SA 4.0 · Original: https://fpc.wisv.ch · Statement adapted for AlgoLens and shared under the same license. · 1 of the 40 original test cases (the largest) are omitted here to keep the problem lightweight.

Nümunələr

Giriş #1

6 4
2 1 2
4 2 4 3 1
3 3 4 2
2 4 1
1 4
3 4 3 2

Çıxış #1

4

Giriş #2

7 3
3 1 2 3
2 2 1
3 3 1 2
3 1 3 2
2 3 2
1 3
2 1 3

Çıxış #2

1

Giriş #3

3 3
3 1 2 3
3 2 3 1
3 3 1 2

Çıxış #3

impossible

Giriş #4

4 3
3 1 2 3
2 1 2
2 2 1
3 2 1 3

Çıxış #4

impossible