#P6113. 【模板】一般图最大匹配

    ID: 5085 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>Special Judge一般图的最大匹配线性代数

【模板】一般图最大匹配

Description

Given an undirected graph with nn vertices and mm edges, find the maximum matching of this graph.

Input Format

The first line contains two positive integers nn and mm, representing the number of vertices and the number of edges in the graph.

The next mm lines each contain two positive integers uu and vv, indicating that there is an undirected edge connecting uu and vv.

Output Format

The first line contains one integer, the size of the maximum matching.

The second line contains nn integers. The ii-th integer denotes the index of the vertex matched with vertex ii. If vertex ii is unmatched, output 00.

If there are multiple solutions, output any one.

10 10
4 3
3 1
4 7
2 10
2 9
3 10
5 9
4 6
1 10
1 7

4
7 9 10 6 0 4 1 0 2 3 

Hint

For 50%50\% of the testdata, n500n \le 500.

For 100%100\% of the testdata, 2n1032 \le n \le 10^3 and 1m5×1041 \le m \le 5 \times 10^4.

This problem has 5 extra test cases.

Hint

To make it easier for you to debug your program, the problem setter provides a very ugly testdata generator here.

Translated by ChatGPT 5