diff --git a/code_study/Baekjoon/python/2239.py b/code_study/Baekjoon/python/2239.py new file mode 100644 index 0000000..d2d7a15 --- /dev/null +++ b/code_study/Baekjoon/python/2239.py @@ -0,0 +1,49 @@ +import sys +input = sys.stdin.readline + +board = [] +emptyAxis = [] + +row_check = [[False]*10 for _ in range(9)] +col_check = [[False]*10 for _ in range(9)] +square_check = [[False]*10 for _ in range(9)] + +def square_idx(r, c) : + return (r//3)*3 + c//3 + +def backTracking(depth) : + if depth == len(emptyAxis) : + for row in board : + print("".join(map(str, row))) + exit(0) + + row, col = emptyAxis[depth] + sqr_idx = square_idx(row, col) + + for num in range(1, 10) : + if not row_check[row][num] and not col_check[col][num] and not square_check[sqr_idx][num] : + board[row][col] = num + row_check[row][num] = True + col_check[col][num] = True + square_check[sqr_idx][num] = True + + backTracking(depth+1) + + board[row][col] = 0 + row_check[row][num] = False + col_check[col][num] = False + square_check[square_idx(row, col)][num] = False + +for i in range(9) : + row = list(map(int, list(input().strip()))) + board.append(row) + for j in range(9) : + num = row[j] + if num == 0 : + emptyAxis.append((i,j)) + else : + row_check[i][num] = True + col_check[j][num] = True + square_check[square_idx(i,j)][num] = True + +backTracking(0) \ No newline at end of file diff --git a/code_study/Baekjoon/python/2252.py b/code_study/Baekjoon/python/2252.py new file mode 100644 index 0000000..fbf72f2 --- /dev/null +++ b/code_study/Baekjoon/python/2252.py @@ -0,0 +1,29 @@ +import heapq +import sys +input = sys.stdin.readline + +N, M = map(int, input().split()) + +graph = [[] for _ in range(N+1)] +inDegree = [0]*(N+1) +for _ in range(M) : + u, v = map(int, input().split()) + graph[u].append(v) + inDegree[v] += 1 + +pq = [] +for i in range(1,N+1) : + if inDegree[i] == 0 : + heapq.heappush(pq, i) + +result = [] +while len(pq) : + current = heapq.heappop(pq) + result.append(str(current)) + + for next in graph[current] : + inDegree[next] -= 1 + if inDegree[next] == 0 : + heapq.heappush(pq, next) + +print(" ".join(result)) \ No newline at end of file