#P17014. [GESP202606 七级] 染色

    ID: 19304 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>图论并查集图遍历二分图2026GESP

[GESP202606 七级] 染色

Problem Description

Student Xiao Yang has an undirected graph GG with nn vertices, where the vertices in GG are numbered 1,2,,n1, 2, \dots, n in order.

Xiao Yang finds that the degree of every vertex in GG is 22. Obviously, there are exactly nn edges in GG.

Xiao Yang wants to color the vertices of GG so that the two endpoints of any edge have different colors.

Xiao Yang wants to know the minimum number of colors needed to color GG under this condition.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer tt, which indicates the number of test cases.

For each test case:

The first line contains a positive integer nn, which indicates the number of vertices in the undirected graph GG.

The next nn lines each contain two positive integers ui,viu_i, v_i, representing an undirected edge connecting vertex uiu_i and vertex viv_i. Integers are separated by a space.

It is guaranteed that there are no multiple edges or self-loops in GG.

Output Format

For each test case, output one line with one integer, which is the minimum number of colors needed to color GG under the condition.

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

Hint

Constraints

For 40%40\% of the test points, it is guaranteed that n500\sum n \le 500, where n\sum n is the sum of nn over all test cases in the input.

For all test points, it is guaranteed that 1t1001 \le t \le 100, 3n1053 \le n \le 10^5, and n105\sum n \le 10^5. It is guaranteed that there are no multiple edges or self-loops in GG.

Translated by ChatGPT 5