#P3552. [POI 2013] SPA-Walk
[POI 2013] SPA-Walk
Description
The names of towns in Byteotia are unique sequences of exactly bits. There are towns in Byteotia, and thus, only sequences of bits do not correspond to any town.
Some pairs of towns are connected by roads. Specifically, two towns are directly linked by a road if and only if their names differ in exactly one bit. The roads do not cross outside of towns.
Byteasar intends to take a stroll — he plans to walk from the town to the town , taking the existing roads. Your task is to determine whether such a walk is possible.
Input Format
The first line contains two integers and (, , , ), separated by a single space. These are the length of the town names in bits and the number of -bit sequences that do not correspond to any town, respectively.
The second line contains two strings, separated by a single space, each consisting of characters 0 and/or 1. These are the names of the towns and .
Each of the next lines contains one sequence of bits that does not correspond to any town. You may assume that and are not among these sequences.
Output Format
Print TAK if it is possible to walk from to , and NIE otherwise.
4 6
0000 1011
0110
0111
0011
1101
1010
1001
TAK
Hint
There are binary strings of length . Two strings are connected by an edge if and only if they differ in exactly one bit. After removing of these strings, determine whether the two specified strings are reachable from each other.
Translated by ChatGPT 5
京公网安备 11011102002149号