Ограничения: время – 2s/4s, память – 32MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод
Послать решение Blockly Посылки Темы Где Обсудить (0)
Anna Graham is a puzzle maker who prides herself in the quality and complexity of her work. She
makes puzzles of all kinds – crosswords, logic problems, acrostics, and word search puzzles, to name but
a few. For each puzzle, she has developed a set of rules which she constrains herself to follow. For word
search puzzles, she insists not only that all the words be connected to one another (as in most word
search puzzles), but also that removing any word from the word list will not cause one or more words
to become disconnected from the rest. (Two words are connected if they contain a common letter in
the grid.) The example word search puzzle on the left satisfies this condition, but the one on the right
does not (removing the word Pascal from the word list disconnects Java from the other two words).
Your job is to write a program that checks to see if Anna's word search problems are up to snuff.
Input
Input will consist of multiple test cases. The first line of each test case contains 3 integers `n` `m` `l`, where
`n` and `m` are the number of rows and columns in the puzzle and `l` is the number of words. Following
this are `n` lines containing `m` uppercase characters each (the puzzle) followed by `l` lines containing one
word each (the word list, in mixed case). Each word in the word list will appear in the puzzle exactly
once. There will be no more than 100 rows and 100 columns in the puzzle and no more than 100 words
to search for. There will be no spaces in the input words.
Output
For each problem instance, output the word Yes or No depending on whether the puzzle satisfies Anna's
constraints.
Sample Input
5 6 3
PBROGR
PASCAL
ASMMIN
GIICON
TCELST
BASIC
LISP
Pascal
5 6 4
PBROJR
PASCAL
ASMMVN
GIICAN
TCELST
BASIC
Java
LISP
Pascal
0 0 0
Source: ACM ICPC ECNA RC 2007