#K51282. Match Scheduling
Match Scheduling
Match Scheduling
You are given n teams and m potential pairs of teams that can play a match against each other. Your task is to determine whether it is possible to schedule a round of matches such that every team plays exactly one match. In other words, you need to select \( \frac{n}{2} \) pairs from the given candidates so that every team appears in exactly one pair.
If n is odd or if it is impossible to form the required pairing using the allowed pairs, output -1.
Input Constraints: \( 1 \leq n, m \leq 10^5 \) (for example).
Example:
Input: 4 3 1 2 2 3 3 4</p>Output: 1 2 3 4
inputFormat
The first line contains two integers, n and m, where n is the number of teams and m is the number of potential pairs. Each of the next m lines contains two integers a and b, indicating that team a can play against team b.
outputFormat
If it is possible to schedule the matches such that every team plays exactly one match, output \( \frac{n}{2} \) lines, each containing two integers representing a pair of teams that will play against each other. The order of pairs or order within a pair does not matter. If a valid scheduling is not possible, output -1.
## sample4 3
1 2
2 3
3 4
1 2
3 4
</p>