CF BUDDY
← Problems·

1829F · Forever Winter

1300 · dfs and similar, graphs, math

Problem: A snowflake graph is generated from two integers xx and yy, both greater than 11, as follows:

  • Start with one central vertex.
  • Connect xx new vertices to this central vertex.
  • Connect yy new vertices to each of these xx vertices.

The snowflake graph above has a central vertex 1515, then x=5x=5 vertices attached to it (33, 66, 77, 88, and 2020), and then y=3y=3 vertices attached to each of those.

Input Format: The first line contains a single integer tt (1t10001 \leq t \leq 1000) — the number of test cases.

The first line of each test case contains two integers nn and mm (2n2002 \leq n \leq 200; 1mmin(1000,n(n1)2)1 \leq m \leq \min\left(1000, \frac{n(n-1)}{2}\right)) — the number of vertices and edges in the graph, respectively.

The next mm lines each contain two integers each uu and vv (1u,vn1 \leq u, v \leq n, uvu \neq v) — the numbers of vertices connected by an edge. The graph does not contain multiple edges and self-loops.

It is guaranteed that this graph is a snowflake graph for some integers xx and yy both greater than 11.

Output Format: For each test case, on a separate line output the values of xx and yy, in that order, separated by a space.

Note: The first test case is pictured in the statement. Note that the output 3 5 is incorrect, since xx should be output before yy.

Sample Cases

Case 1

Input

3
21 20
21 20
5 20
13 20
1 3
11 3
10 3
4 8
19 8
14 8
9 7
12 7
17 7
18 6
16 6
2 6
6 15
7 15
8 15
20 15
3 15
7 6
1 2
1 3
2 4
2 5
3 6
3 7
9 8
9 3
3 6
6 2
2 1
5 2
2 7
4 3
3 8

Output

5 3
2 2
2 3

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback