Victory Through Synergy
Time limit4sMemory limit1024 MB
Place 10 players on the nodes of a given graph so that every node's synergy score is at least its degree, or report that no such placement exists.
- Level
Medium4 of 10
- Topics
- Brute force, Graph, Backtracking
- Solved
- No attempts yet
Statement

Johnny has been placed in a fantasy soccer league and wants the strongest possible team. There are no goalkeepers in this league.
His team has 10 players. For each player, he knows the country, the league, and the team.
Johnny knows these synergy rules:
- Two players from the same country are linked with a synergy score of .
- Two players in the same league are linked with a synergy score of .
- Two players on the same team are linked with a synergy score of .
- Two players from the same country and in the same league are linked with a synergy score of .
- Two players from the same country and on the same team are linked with a synergy score of .
A team can only be in one league, and no two teams share a name unless they are the same team.
The players are placed on the 10 nodes of an undirected graph called the formation. Each node holds exactly one player. The degree of a node is the number of links attached to it. The synergy score of a node is the sum of the synergy scores of all links attached to it. A player gets synergy from the players on the nodes linked to that player.
A team is perfect if and only if every player sits on a node whose synergy score is at least the node's degree.
Given a formation and Johnny's players, determine whether Johnny can arrange the players into a perfect team.
Input
The first line contains an integer (), the number of links in the formation.
Each of the next lines contains two integers and (, ), meaning nodes and are linked.
Each of the next 10 lines contains four strings: player name, country, league, and team. Each string is non-empty, has no spaces, and is at most 15 characters long. The strings are separated by single spaces.
Output
Print yes if Johnny can arrange the players into a perfect team. Otherwise, print no.