Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions Baekjoon/minha/17142_연구소3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from itertools import combinations
from collections import deque

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

def bfs(comb):
q = deque()
visited = [[-1] * N for _ in range(N)]

for y, x in comb:
q.append((y, x))
visited[y][x] = 0

while q:
for _ in range(len(q)):
cy, cx = q.popleft()
for i in range(4):
ny = cy + dy[i]
nx = cx + dx[i]
if 0 <= ny < N and 0 <= nx < N and visited[ny][nx] == -1 and lab[ny][nx] != 1:
q.append((ny, nx))
visited[ny][nx] = visited[cy][cx] + 1

for i, j in virus:
if (i, j) not in comb:
visited[i][j] = 0

for i in range(N):
for j in range(N):
if lab[i][j] == 0 and visited[i][j] == -1:
return 1e9

return max(map(max, visited))

N, M = map(int, input().split())
answer = 1e9

lab = []
virus = []
for r in range(N):
row = list(map(int, input().split()))
for c in range(N):
if row[c] == 2:
virus.append((r, c))
lab.append(row)

for comb in combinations(virus, M):
res = bfs(comb)
if res != -1e9:
answer = min(answer, res)

if answer == 1e9:
print(-1)
else:
print(answer)
36 changes: 36 additions & 0 deletions Baekjoon/minha/1967_트리의지름.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from collections import deque

def find_max(node):
q = deque()
visited = [False] * (n + 1)

q.append((node, 0))
visited[node] = True
m_weight = 0
m_node = -1

while q:
node, weight = q.popleft()
for n_node, n_weight in graph[node]:
s_weight = weight + n_weight
if not visited[n_node]:
q.append((n_node, s_weight))
visited[n_node] = True
if m_weight < s_weight:
m_weight = s_weight
m_node = n_node

return m_node, m_weight

n = int(input())
graph = [[] for _ in range(n + 1)]

for _ in range(n - 1):
p, c, w = map(int, input().split())
graph[p].append((c, w))
graph[c].append((p, w))

max_node, _ = find_max(1)
_, answer = find_max(max_node)

print(answer)
16 changes: 16 additions & 0 deletions Baekjoon/minha/9935_문자열폭발.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
my_str = input()
bomb_str = input()

stack = []

for i in range(len(my_str)):
stack.append(my_str[i])
if ''.join(stack[-len(bomb_str):]) == bomb_str:
# stack = stack[:-len(bomb_str)] 시간 초과 남
for _ in range(len(bomb_str)):
stack.pop()

if stack:
print(''.join(stack))
else:
print('FRULA')