Tournament
InterviewTime limit1sMemory limit1024 MB
Given a bracket order A and k proposed orders, check whether each proposed order makes every pair of players meet in the same round as A.
- Level
Medium5 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
players ( is a power of two) play in a single-elimination tournament. Each player receives a distinct number with . The bracket is built as follows. The player numbers are drawn one by one, and the -th drawn number is . In the first round, player plays , plays , and so on, until winners remain. In the second round, the first winner plays the second, the third plays the fourth, and so on, until winners remain. This continues until one tournament champion is left. Some players find certain schedules unsuitable, so they propose replacing the sequence with another sequence . The remaining players want the tournament to stay identical to the original. That means every pair of players must be able to meet in the same round, provided both keep winning until then.
Input
The first line contains two integers and , the number of players and the number of proposed sequences. The second line contains the sequence , where the -th number is . The next lines contain the sequences (). On line , the -th number is the proposed value for ().
Output
Print lines, each containing one word: TAIP if the tournament defined by is identical to the tournament defined by , or NE otherwise.
Constraints
, is a power of two, , . For , and .