#K55657. Match Scheduling Tournament

    ID: 30024 Type: Default 1000ms 256MiB

Match Scheduling Tournament

Match Scheduling Tournament

An event is organized where players must be scheduled for matches based on given preferences. Each preference is a pair of players \( (u,v) \) who should compete against each other. The scheduling must ensure that no player faces the same opponent more than once and that the total number of matches equals the specified \( M \). If it is impossible to form the required schedule, output -1.

Formally, given \( N \) players, \( M \) match preferences, and a list of pairs \( (u, v) \), you are to construct a schedule such that exactly \( M \) unique matches are played. If a valid schedule exists, output any one valid configuration; otherwise, output \(-1\).

inputFormat

The first line contains two integers \( N \) and \( M \) representing the number of players and the number of match preferences respectively.

Each of the following \( M \) lines contains two integers \( u \) and \( v \), indicating that player \( u \) should play against player \( v \).

outputFormat

If a valid schedule exists containing exactly \( M \) matches, output \( M \) lines where each line contains two integers representing a match.

If no valid schedule can be formed, output \(-1\).

## sample
4 3
1 2
2 3
3 4
1 2

2 3 3 4

</p>