This is an output-only problem.
There are $n$ people, and several gatherings have been organized among them. Initially, no two people are friends. In each gathering, every pair of attendees becomes friends. Now, you have forgotten how many gatherings were held and who attended each gathering, but you remember which pairs of people ended up as friends. You want to reconstruct the process of the gatherings. Clearly, the solution is not unique, but you aim to find one that minimizes the number of gatherings. The fewer the gatherings, the higher the score, as detailed in the scoring criteria.
Input Format
All input data friends1.in ~ friends10.in
are provided in the given files, corresponding to $10$ test cases.
For each dataset, the first line contains two positive integers $n$ and $m$, representing the number of people and the number of pairs of friends, respectively.
The following $m$ lines each contain two numbers $x$ and $y$, indicating that person $x$ and person $y$ are friends.
Output Format
Output your results to friends1.out ~ friends10.out
.
The first line should contain a positive integer $k$, representing the number of gatherings in your solution.
The next $k$ lines should each represent a gathering. Each line should start with a number $r$, indicating the number of participants in the gathering. Then, $r$ distinct positive integers should follow, representing the set of people who attended the gathering.
You must ensure that after organizing these $k$ gatherings, the $m$ pairs of friends are satisfied, and that no additional people become friends.
You also need to ensure that $k \leq m$ and that the sum of the number of participants in all gatherings does not exceed $2m$.
Sample Input
4 5
1 2
1 3
2 3
2 4
3 4
Sample Output
2
3 1 2 3
3 2 3 4
Sample Explanation
There are two gatherings in total.
In the first gathering, persons $1$, $2$, and $3$ attended, so $(1,2)$, $(2,3)$, and $(1,3)$ became friends after the gathering.
In the second gathering, persons $2$, $3$, and $4$ attended, so $(2,3)$, $(3,4)$, and $(2,4)$ became friends after the gathering.
After the gatherings, $(1,2)$, $(1,3)$, $(2,3)$, $(2,4)$, and $(3,4)$ became friends, which matches the input.
It can be proven that the minimum value of $k$ is $2$, so the sample output is the optimal solution for this case (though other valid solutions with larger $k$ exist).
Data Range
Test Case |
$n=$ |
$p=$ |
Special Property |
1 |
$6$ |
$\frac 12$ |
2 |
$10$ |
$\frac 12$ |
3 |
$50$ |
None |
A |
4 |
$100$ |
$\frac 13$ |
5 |
$100$ |
$\frac 12$ |
6 |
$500$ |
$\frac 15$ |
7 |
$500$ |
$\frac 12$ |
8 |
$1000$ |
$\frac 15$ |
9 |
$1000$ |
$\frac 13$ |
10 |
$1000$ |
$\frac 12$ |
Special Property A: The people can be divided into two groups such that no one within the same group is friends with each other.
If $p$ has a value, it means that in this test case, the data was generated as follows: for every pair of people $i, j(i < j)$, $i$ and $j$ have a probability $p$ of being friends, and a probability $1-p$ of not being friends.
Scoring Criteria
If your output does not meet the problem's requirements, the score will be $0$.
If your output is correct, let $Z$ be the number of gatherings in your solution. For this test case, your score is calculated as follows:
- If $Z \leq Z_0$, the score is $S$.
- If $Z > Z_0$, the score is $S \times \left(\frac{Z_0}{Z}\right)^3$.
The parameters $Z_0$ and score $S$ for each test case are as follows:
Test Case |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
$Z_0$ |
$4$ |
$9$ |
$321$ |
$288$ |
$208$ |
$3935$ |
$2621$ |
$12386$ |
$11198$ |
$8486$ |
$S$ |
$4$ |
$8$ |
$6$ |
$9$ |
$9$ |
$11$ |
$11$ |
$13$ |
$13$ |
$16$ |
In the folder containing friends1.in ~ friends10.in
, after storing your answers in friends1.out ~ friends10.out
, you can use the provided checker.cpp
file to check your current score for each test case.