Soccer Bets
Time limit1sMemory limit128 MB
16 shuffled match results with scores are given; reconstruct the single-elimination bracket and report the tournament winner.
- Level
Medium5 of 10
- Topics
- Graph, Implementation, Simulation, Hash map
- Solved
- No attempts yet
Problem
The group stage of the FIFA World Cup is over, and the sixteen teams in the round of sixteen are known. My boss has had every remaining game analysed and has bet on the whole rest of the tournament, writing the outcome of each match on a single sheet of paper. My job was to take his bets to the nearest betting office and stake 1,000 dollars. Being nervous with so much cash in my pockets, I tripped (I am a little clumsy) and the bets got shuffled. So now I no longer know whether a given bet belongs to the final, a semi-final, or some other match.
I do not want to disappoint my boss, so I have decided to place just one bet: on the winner of the tournament. All I know is that in each round the teams that win advance to the next round (a team wins if it scores more goals than its opponent), and the losing teams are knocked out. The only exception is the semi-finals, whose two losers still play each other for third place. In total, then, there are 16 matches.
Based on my boss's bets, can you tell me which team will win the World Cup?
Input
The first line contains the number of test cases . Each test case consists of 16 lines that describe the matches in random order. A match is described as t1 t2 g1 g2, where and are the names of the two teams (each abbreviated as exactly three uppercase letters) and and are the goals scored by and respectively.
Output
For each test case, print a single line with the team that will win the FIFA World Cup (according to my boss's analysis, which is always correct).