politics
No party has a majority in
the Romanian parliament, so approving laws is a very tedious process.
There are n MPs in the parliament, which we will identify with numbers from 1 to n.
What we want is to form a coalition made up of several parties. This coalition
must be a majority coalition (the total number of MPs from the coalition's parties
has to be at least equal to n/2+1)
.
Because when forming a coalition negotiations take longer the more parties are
involved, we want a majority coalition formed from a minimum number of political
parties.
A party will be identified by the party president's number (this is the MP of said party that has the smallest number).
Task
Write a program that determines a majority coalition formed from a minimum number of parties.
Input Data
Input file politics.in
contains on the first line two positive integers separated by a space, n
and m, representing the total
number of MPs and, respectively, the number of relations on the following m
lines of the input file. Each of the following m
lines contains two positive integers x
and y, numbers between 1
and n, separated by a space,
meaning "MP x and MP y
are from the same party".
Output Data
Output file politics.out
will contain on the first line a positive integer nr,
representing the minimum number of parties that will form the coalition. The
second line will contain nr positive
integers, each separated by a space, representing the identification numbers
of the coalition party presidents.
Constraints
0 < n <= 1000
0 < m <= 50000
Examples
politics.in | politics.out | Explanation |
11 7 |
2 1 4 |
Party having president 1 is represented by MPs 1, 2 and 11. Party having president 4 is represented by MPs 4, 5, 7 and 9. The coalition has a total of 7 MPs; therefore it is a majority coalition. |
Time limit: 0.1 seconds/test
prof. Emanuela Cerchez
Computer Science High School "Grigore Moisil" Iasi
Contact:emanuela.cerchez@gmail.com