QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100

#8757. Graph

統計

Given an undirected graph with $n$ vertices and $m$ edges, let $k=\lceil\frac{m}{n-1}\rceil$. You need to determine whether there exist two distinct vertices $u$ and $v$ such that there are $k$ edge-disjoint paths between them. If such $u$ and $v$ can be found, you need to output these paths. If multiple construction schemes exist, you may output any one of them.

Note that the input may contain multiple edges between the same pair of vertices. If there are $s$ edges between $u$ and $v$, you may treat these as $s$ distinct edges that can be traversed.

It is guaranteed that the input does not contain self-loops.

Input

The input is read from standard input.

This problem contains multiple test cases.

The first line contains a positive integer $T(1\le T\le 10^4)$, representing the number of test cases.

For each test case, the first line contains two positive integers $n, m(2\le n\le 10^5, 1\le m\le 2\times 10^5)$, representing the number of vertices and edges. The next $m$ lines each contain two positive integers $u, v(1\le u, v\le n, u\not=v)$, describing an edge between $u$ and $v$.

It is guaranteed that $\sum n\le 10^5$ and $\sum m\le 2\times 10^5$, where $\sum n$ and $\sum m$ are the sums of $n$ and $m$ over all test cases in a single test file, respectively.

Output

The output is written to standard output.

For each test case, if no such $u, v$ exist, output a single integer -1 on a line. Otherwise, first output two positive integers $u$ and $v$ on a line, representing the two vertices you found. Then, output $k=\lceil\frac{m}{n-1}\rceil$ lines. Each line should start with a positive integer $t$, representing the length of the chosen path, followed by $t$ positive integers $x_1, x_2, \dots, x_t$, representing the path $x_1\to x_2\to\cdots\to x_t$. You must ensure that $x_1=u$ and $x_t=v$, and that the $k$ output paths are edge-disjoint.

Examples

Input 1

3
3 1
1 3
4 7
1 2
2 3
3 4
4 1
1 3
2 4
1 4
5 5
1 2
2 3
3 4
4 5
3 5

Output 1

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

Note 1

In the first test case, there exists $\lceil\frac{m}{n-1}\rceil=\lceil\frac{1}{3-1}\rceil=1$ edge-disjoint path from $1$ to $3$, which is $1\to 3$.

In the second test case, there exist $\lceil\frac{m}{n-1}\rceil=\lceil\frac{7}{4-1}\rceil=3$ edge-disjoint paths from $1$ to $4$: $1\to 2\to 3\to 4$, $1\to 4$, and $1\to 4$. Note that although the edge $1\to 4$ is traversed twice, it was provided twice in the input, so they are considered distinct edges.

In the third test case, there exist $\lceil\frac{m}{n-1}\rceil=\lceil\frac{5}{5-1}\rceil=2$ edge-disjoint paths from $3$ to $5$: $3\to 4\to 5$ and $3\to 5$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.