λ¬Έμ
λ°±μ€ μ¨λΌμΈ μ μ§ - 15723λ²
νμ΄ κ³Όμ
nλ¨ λ
Όλ²
μ λ§μ‘±νλμ§ νλ¨νλ λ¬Έμ μ
λλ€.
μ°μ μ£Όμ΄μ§ λ
Όμ λ₯Ό λ°νμΌλ‘ λ°©ν₯ κ·Έλνλ₯Ό μμ±ν©λλ€.
μ΄ν νΉμ λ
Όλ²μ΄ λͺ¨μμ΄ μλμ§ νλ¨νκΈ° μν΄μλ a is d
μΌ λ a
μμ d
μ λλ¬ κ°λ₯νμ§ νλ¨νλ©΄ λ©λλ€.
λ°λΌμ μμ±ν κ·Έλνμ νλ‘μ΄λ μμ¬
μκ³ λ¦¬μ¦μ μ΄μ©ν΄μ λͺ¨λ μ μ μ λν΄ λλ¬ κ°λ₯μ±μ νλ¨νλ©΄ λ©λλ€.
μ½λ
import sys
N = int(input())
graph = [[0] * 26 for _ in range(26)]
for _ in range(N):
frm, to = list(sys.stdin.readline().strip().split(' is '))
graph[ord(frm) - ord('a')][ord(to) - ord('a')] = 1
M = int(input())
questions = []
for _ in range(M):
frm, to = list(sys.stdin.readline().strip().split(' is '))
questions.append([ord(frm) - ord('a'), ord(to) - ord('a')])
def floyd():
global graph
for k in range(26):
for u in range(26):
for v in range(26):
graph[u][v] = graph[u][v] or (graph[u][k] and graph[k][v])
def solution():
floyd()
for frm, to in questions:
if graph[frm][to]:
print('T')
else:
print('F')
solution()
λ°μν
'π algorithm > boj' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
BOJ 18238 - ZOAC2 (0) | 2021.03.18 |
---|---|
BOJ 14754 - Pizza Boxes (0) | 2021.03.18 |
BOJ 14496 - κ·Έλ, κ·Έλ¨Έκ° λμ΄ (0) | 2021.03.16 |
BOJ 9311 - Robot in a Maze (0) | 2021.03.14 |
BOJ 20005 - 보μ€λͺ¬μ€ν° μ 리ν (0) | 2021.03.14 |
π¬ λκΈ