Hockey in the Urals
Time limit1sMemory limit1024 MB
Given two perfect matchings on N teams, find K teams containing no matched pair from either round, or report that none exists.
- Level
Medium7 of 10
- Topics
- Graph, Greedy, Implementation, Math
- Solved
- No attempts yet
Problem
To promote hockey in the Urals and raise the skill of its hockey teams, an All-Ural tournament was organized. hockey teams from cities of the Urals were invited to take part.
After the first two rounds, in each of which every team played one match, it turned out that there were too many teams. The organizers decided to admit to further participation only teams, no two of which had met in the first two rounds.
Write a program that finds a set of teams satisfying the conditions, or reports that this is impossible. If several suitable sets exist, find any one of them.
Input
The first line of the input file contains the number (, is even).
The next lines describe all the matches played. Each match description consists of two natural numbers not exceeding , the numbers of the teams that played the match. The first of them correspond to matches of the first round, and the rest to matches of the second round.
The last line of the input file contains one number ().
It is guaranteed that each team played exactly two matches: one in the first round and one in the second.
Output
The output file must contain either the single number if no solution exists, or distinct numbers, the numbers of the selected teams.