Under construction

Still being built. Things may change

Victory Through Synergy

Time limit4sMemory limit1024 MB

Summary
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:

  1. Two players from the same country are linked with a synergy score of 11.
  2. Two players in the same league are linked with a synergy score of 11.
  3. Two players on the same team are linked with a synergy score of 22.
  4. Two players from the same country and in the same league are linked with a synergy score of 22.
  5. Two players from the same country and on the same team are linked with a synergy score of 33.

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 cc (0≤c≤450 \leq c \leq 45), the number of links in the formation.

Each of the next cc lines contains two integers aa and bb (0≤a,b<100 \leq a, b < 10, a≠ba \neq b), meaning nodes aa and bb 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.

Examples2

  1. Example 1

    Input
    15
    0 1
    1 2
    2 3
    0 4
    1 5
    2 6
    3 7
    4 5
    5 6
    6 7
    4 8
    5 8
    6 9
    7 9
    8 9
    Griezmann France LaLiga AtleticoMadrid
    Benzema France LaLiga RealMadrid
    Ntep France Ligue1 StadeRennais
    Sissoko France PremierLeague Spurs
    Tolisso France Ligue1 Lyon
    Diarra France Ligue1 OM
    Evra France CalcioA Juventus
    Koscielny France PremierLeague Arsenal
    Varane France LaLiga RealMadrid
    Sagna France PremierLeague ManCity
    
    Expected output
    yes
    
  2. Example 2

    Input
    15
    0 1
    1 2
    2 3
    0 4
    1 5
    2 6
    3 7
    4 5
    5 6
    6 7
    4 8
    5 8
    6 9
    7 9
    8 9
    PlayerA France A1 A1-1
    PlayerB France B1 B1-1
    PlayerC France C1 C1-1
    PlayerD France D1 D1-1
    PlayerE France E1 E1-1
    PlayerF France F1 F1-1
    PlayerG France G1 G1-1
    PlayerH France H1 H1-1
    PlayerI France I1 I1-1
    PlayerJ Germany J1 J1-1
    
    Expected output
    no