Codeforces Global Round 29 (Div. 1 + Div. 2)
H
Maxflow GCD Coloring
Codeforces
3500
原题
← GI1 →
翻译中…

Consider an undirected graph $G$ with $n$ vertices and positive integer capacities on its edges. We denote by $\textsf{maxflow}(u, v)$ the value of the maximum flow in the graph from source $u$ to sink $v$. We say that such a graph $G$ is good if there exists a positive integer $d \geq 2$ such that $d$ divides each of the $n \cdot (n-1)$ values of $\textsf{maxflow}(u, v)$ for all pairs $(u, v)$ of distinct vertices of $G$. Note that, in particular, any graph without edges is good.

翻译中…

You are given a graph, and you have to color its vertices so that, for each color, the subgraph induced$^{\text{∗}}$ by the vertices of that color is good. Find such a coloring with the minimum possible number of colors.

翻译中…

$^{\text{∗}}$Subgraph induced by a set of vertices $S$ is another graph, whose vertices are $S$ and whose edges are all of the edges, from the original graph, connecting pairs of vertices in $S$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \leq n \leq 50$, $0 \leq m \leq \frac{n(n-1)}{2}$), the number of vertices and the number of edges of the graph.

翻译中…

The next $m$ lines each contain three integers $u$, $v$, $w$ ($1 \leq u, v \leq n$, $1 \leq w \leq 10^6$), denoting that there is an edge connecting vertices $u$ and $v$ with capacity $w$. It is guaranteed that there are no self-loops or multiple edges between the same vertices.

翻译中…

It is guaranteed that the sum of $n^4$ over all test cases does not exceed $50^4$.

翻译中…

It can be shown that other limitations imply that the sum of $m$ over all test cases does not exceed $50\,000$, so you don't need to worry about the size of the input.

翻译中…

Output

翻译中…

For each test case, output one integer $c$, the minimum possible number of colors. Then, output $2c$ lines, describing the coloring. For each $1 \leq i \leq c$, you must output two lines: one line with the number of vertices $k_i$ colored with the $i$-th color, followed by one line with $k_i$ integers, the vertices colored with the $i$-th color.

翻译中…

If there are multiple solutions, print any of them.

翻译中…

Note

翻译中…
翻译中…

In the answer to the first test case, the subgraph induced by the first color has no edges, and the subgraph induced by the second color has only one edge with capacity $6$; therefore, both subgraphs are good.

翻译中…

In the second test case, the whole graph is good since the value of $\mathsf{maxflow}$ between any pair of vertices is divisible by $3$.

翻译中…

样例

Input #1
2
5 5
1 2 2
2 3 3
3 4 4
4 5 5
5 1 6
6 7
1 2 2
1 3 2
1 4 2
2 5 1
3 5 1
4 5 1
5 6 6
Output #1
2
2
2 4
3
1 3 5
1
6
1 2 3 4 5 6
InputCopy OutputCopy
题目信息
题号
2147H
时间限制
2 s
内存限制
256 MB
标签
构造
网络流
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。