import sys
from collections import deque
input = sys.stdin.readline
n,k = map(int,input().split())
bd = [[] for _ in range(n)]
lst = []
for _ in range(n):
cur = input().rstrip()
lst.append(set([cur[i-k:i] for i in range(k,len(cur)+1)]))
for i,c in enumerate(lst):
for j,s in enumerate(lst[i+1:],i+1):
if c.intersection(s):
bd[i].append(j)
bd[j].append(i)
ans = [0]*n
vis = [0]*n
for i in range(n):
if ans[i]: continue
ans[i] = vis[i] = 1
q = deque([i])
while q:
cur = q.popleft()
pos = 3-ans[cur]
for nxt in bd[cur]:
if ans[nxt] == pos:
continue
elif ans[nxt]:
exit(print('No'))
ans[nxt] = pos
q.append(nxt)
if sum(ans) == n:
ans[-1] = 2
print('Yes')
print(*ans,sep='\n')
Compilation message (stdout)
Compiling 'onward.py'...
=======
adding: __main__.pyc (deflated 35%)
=======
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |