diff --git "a/BAEKJOON/15686_\354\271\230\355\202\250_\353\260\260\353\213\254.py" "b/BAEKJOON/15686_\354\271\230\355\202\250_\353\260\260\353\213\254.py" new file mode 100644 index 0000000..73cf658 --- /dev/null +++ "b/BAEKJOON/15686_\354\271\230\355\202\250_\353\260\260\353\213\254.py" @@ -0,0 +1,24 @@ +from itertools import combinations +import sys +def input(): return sys.stdin.readline().strip() + +N, M = map(int, input().split()) +data = [input().split() for _ in range(N)] +homes, chickens = [], [] +for i in range(N): + for j in range(N): + if data[i][j] == '1': + homes.append((j, i)) + elif data[i][j] == '2': + chickens.append((j, i)) + +answer = float('inf') +for arr in combinations(chickens, M): + length = 0 + for hx, hy in homes: + l = float('inf') + for cx, cy in arr: + l = min(l, abs(cx - hx) + abs(cy - hy)) + length = length + l + answer = min(answer, length) +print(answer) \ No newline at end of file diff --git "a/BAEKJOON/1707_\354\235\264\353\266\204_\352\267\270\353\236\230\355\224\204.py" "b/BAEKJOON/1707_\354\235\264\353\266\204_\352\267\270\353\236\230\355\224\204.py" new file mode 100644 index 0000000..e259f4d --- /dev/null +++ "b/BAEKJOON/1707_\354\235\264\353\266\204_\352\267\270\353\236\230\355\224\204.py" @@ -0,0 +1,43 @@ +from collections import deque +import sys +def input(): return sys.stdin.readline().strip() + +K = int(input()) +for _ in range(K): + V, E = map(int, input().split()) + + edges = [[] for _ in range(V + 1)] + for _ in range(E): + u, v = map(int, input().split()) + edges[u].append(v) + edges[v].append(u) + + check = [0] * (V + 1) + answer = False + for i in range(1, V + 1): + if check[i]: + continue + + check[i] = 1 + queue = deque([i]) + while queue: + here = queue.popleft() + + for there in edges[here]: + if check[there] == check[here]: + answer = True + break + + if check[there]: + continue + + check[there] = 3 - check[here] + queue.append(there) + + if answer: + break + + if answer: + break + + print("NO" if answer else "YES") \ No newline at end of file