QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 256 MB Total points: 100

#13317. Walk

统计

The names of towns in Byteotia are unique sequences of exactly $n$ bits. There are $2^n-k$ towns in Byteotia, and thus, only $k$ sequences of $n$ bits do not correspond to any town.

Some pairs of towns are connected with roads. Specifically, two towns are directly linked by a road if and only if their names differ in a single bit. The roads do not cross outside of towns.

Byteasar intends to take a stroll - he intends to walk from the town $x$ to the town $y$, taking the existing roads. Your task is to write a program that will determine if such a walk is possible.

Input Format

In the first line of the standard input, there are two integers, $n$ and $k$ ($1 ≤ n ≤ 60$, $0 ≤ k ≤ 1\,000\,000$, $k ≤ 2^n-1$, $n\cdot k ≤ 5\,000\,000$), separated by a single space. These are the length of town names in bits and the the number of n-bit sequences that do not correspond to any town, respectively. In the second line, there are two strings, separated by a single space, each consisting of $n$ characters 0 and/or 1. These are the names of the towns $x$ and $y$. In the $k$ lines that follow, all the sequences of $n$ bits that do not correspond to any town are given, one sequence per line. Each such sequence is a string of $n$ characters 0 and/or 1. You may assume that $x$ and $y$ are not among those $k$ sequences.

Output Format

Your program should print to the standard output the word TAK (Polish for yes) if walking from the town $x$ to the town $y$ is possible, and the word NIE (Polish for no) otherwise.

Example

Input

4 6
0000 1011
0110
0111
0011
1101
1010
1001

Output

TAK

Input 2

2 2
00 11
01
10

Output 2

NIE

The following are two examples of a walk from 0000 to 1011:

  • 0000 → 1000 → 1100 → 1110 → 1111 → 1011
  • 0000 → 0100 → 1100 → 1110 → 1111 → 1011.
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.