Binary Strings

시간 제한2초메모리 제한2048 MB

요약
주어진 s 문자열 두 개를 부분 문자열로 포함하면서 어떤 t 문자열도 부분 문자열로 포함하지 않는 이진 문자열이 존재하는지 판정한다.
난이도

어려움10점 중 9점

유형
문자열 매칭, 그래프, DFS, 그리디
정답자
아직 제출이 없습니다

문제

Given nn non-empty binary strings s_1,s_2,…,s_ns\_1, s\_2, \ldots, s\_n and another mm non-empty binary strings t_1,t_2,…,t_mt\_1, t\_2, \ldots, t\_m, determine if there exists such a binary string SS that:

  • There exist ii and jj such that 1≤i<j≤n1 \le i < j \le n, and both strings s_is\_i and s_js\_j appear in SS as substrings.
  • For all ii such that 1≤i≤m1 \le i \le m, string t_it\_i does not appear in SS as a substring.

입력

The first line contains one integer TT (1≤T≤1051\le T \le 10^5) denoting the number of test cases. For each test case:

The first line contains two integers nn and mm (2≤n≤1052 \le n \le 10^5, 1≤m≤1051 \le m \le 10^5).

The following nn lines contain non-empty binary strings s_1,s_2,…,s_ns\_1, s\_2, \ldots, s\_n, one per line.

The following mm lines contain non-empty binary strings t_1,t_2,…,t_mt\_1, t\_2, \ldots, t\_m, one per line.

For the total sums over all test cases, it is guaranteed ∑n+∑m≤105\sum n + \sum m \le 10^5 and that ∑∣s_i∣+∑∣t_i∣≤106\sum |s\_i| + \sum |t\_i| \le 10^6.

출력

For each test case, output a line containing a single string: "Yes" (without quotes) if such a binary string SS exists, or "No" (without quotes) if not.

힌트

For the first case, one possible string is "0100", where s_1=s\_1 = 100 and s_3=s\_3 = 010 appear in it, but t_1=t\_1 = 1001 and t_2=t\_2 = 000 don't appear.

예제1

  1. 예제 1

    입력
    2
    3 2
    100
    001
    010
    1001
    000
    2 4
    100
    001
    010
    1001
    000
    11
    
    예상 출력
    Yes
    No