Skip to content

Commit

Permalink
22.09.03
Browse files Browse the repository at this point in the history
  • Loading branch information
delena0702 authored Sep 3, 2022
1 parent 4d28cf1 commit 533b496
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
24 changes: 24 additions & 0 deletions BAEKJOON/15686_치킨_배달.py
Original file line number Diff line number Diff line change
@@ -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)
43 changes: 43 additions & 0 deletions BAEKJOON/1707_이분_그래프.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 533b496

Please sign in to comment.