Skip to content

Commit

Permalink
Merge pull request #29 from INIT-Algorithm/yoojin
Browse files Browse the repository at this point in the history
#26 : Week6_유진이티
  • Loading branch information
yjhss authored May 30, 2023
2 parents 166896e + 1c33649 commit 06ba83d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 이티유진/10026_적록색약.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys
from collections import deque

n = int(sys.stdin.readline())
visited = [[False] * n for _ in range(n)]
grid = [list(map(str, input())) for _ in range(n)]
queue = deque()

dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

def bfs(x, y):
queue.append([x, y])
while queue:
x, y = queue.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < n and 0 <= ny < n and not visited[nx][ny] and grid[nx][ny] == grid[x][y]:
queue.append([nx, ny])
visited[nx][ny] = True

count = 0
for i in range(n):
for j in range(n):
if not visited[i][j]:
bfs(i, j)
count += 1
print(count, end=' ')

for i in range(n):
for j in range(n):
if grid[i][j] == 'R':
grid[i][j] = 'G'

visited = [[False] * n for _ in range(n)]

count = 0
for i in range(n):
for j in range(n):
if not visited[i][j]:
bfs(i, j)
count += 1
print(count)
27 changes: 27 additions & 0 deletions 이티유진/15723_n단 논법.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys

input = sys.stdin.readline
INF = int(1e9)

N = int(sys.stdin.readline())

alphabet = "abcdefghijklmnopqrstuvwxyz"
n = len(alphabet)
graph = [[INF] * n for _ in range(n)]

for _ in range(N):
a, b = map(alphabet.index, input().rstrip().split(" is "))
graph[a][b] = 1

for k in range(n):
for i in range(n):
for j in range(n):
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

M = int(input())
for _ in range(M):
a, b = map(alphabet.index, input().rstrip().split(" is "))
if graph[a][b] == INF:
print("F")
else:
print("T")

0 comments on commit 06ba83d

Please sign in to comment.