There are N cities numbered from 0 to N-1, and undirected roads connect some pairs of cities.
Each road has a priority. Consider two roads (A, B) and (C, D), where A < B and C < D. If the tuple (A, B) is lexicographically smaller than (C, D), then road (A, B) has higher priority. Lexicographic order means that at the first position where two tuples differ, the tuple with the smaller value is smaller.
A road set is written with its roads sorted from highest priority to lowest priority. Road sets are also compared lexicographically by those ordered road tuples. A road set is connected if every city can be reached from every other city using only roads in the set.
Find the highest-priority connected road set that contains exactly M roads.