-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
DICTIONARY self review 
1. ํด๊ฒฐ ์๋ ๊ณผ์
๊ทธ๋ํ๋ก ํํํ๊ณ ์์์ ๋ ฌ์ ํตํด ๋ฌธ์๋ค์ ์์๋ฅผ ๊ตฌํ ์ ์์ ๊ฒ์ด๋ผ ์๊ฐํ์ต๋๋ค. ๋ํ, b->a->b ์ฒ๋ผ ์ฌ์ดํด์ด ํ์ฑ๋๋ ๊ฒฝ์ฐ๋ ๊ณ ๋ คํด์ค์ผ๊ฒ ๋ค๊ณ ์๊ฐํ์ต๋๋ค.
2. ์์ฑํ ์ฝ๋์ ์ค๋ช
T = int(input().rstrip())
for _ in range(T):
graph = defaultdict(set)
N = int(input().rstrip())
words = []
visited = {}
for _ in range(N):
words.append(input().rstrip())
# ์ด์ ๋ฌธ์์ด๊ณผ ๋น๊ตํ๋ฉด์ ๋ค๋ฅด๋ค๋ฉด ๊ทธ๋ํ์ ์ถ๊ฐ์์ผ์ฃผ๊ธฐ
prev = ""
for word in words:
for i in range(min(len(prev), len(word))):
if prev[i] != word[i]:
graph[prev[i]].add(word[i])
visited[prev[i]] = None
visited[word[i]] = None
break
prev = word3. ๋งํ ์ ๋ฐ ๊ฐ์ ์ฌํญ
์ดํ dfs ๊ตฌํ ์ดํ ์ญ๋ฐฉํฅ์ผ๋ก reverse ์ํค๋ ๋ถ๋ถ์ ๊ตฌํํ์ง ๋ชปํ์ต๋๋ค