304559: CF868A. Bark to Unlock
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Bark to Unlock
题意翻译
- 给定一个长度为 $2$ 的字符串 $s$,以及 $n$ 个长度为 $2$ 的字符串 $t_1,t_2,t_3,...,t_n$,问你是否能够通过将这 $n$ 个字符串中的任意一些字符串(**可以将一个字符串使用多次**)拼接成一个大字符串 $a$,使得 $s$ 是 $a$ 的子串。 - $1\leqslant n\leqslant 100$。题目描述
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters. Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark $ n $ distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.输入输出格式
输入格式
The first line contains two lowercase English letters — the password on the phone. The second line contains single integer $ n $ ( $ 1<=n<=100 $ ) — the number of words Kashtanka knows. The next $ n $ lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.
输出格式
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
输入输出样例
输入样例 #1
ya
4
ah
oy
to
ha
输出样例 #1
YES
输入样例 #2
hp
2
ht
tp
输出样例 #2
NO
输入样例 #3
ah
1
ha
输出样例 #3
YES