Skip to content

Commit

Permalink
Merge pull request #251 from AlgoLeadMe/79-tgyuuAn
Browse files Browse the repository at this point in the history
79-tgyuuAn
  • Loading branch information
tgyuuAn authored Nov 11, 2024
2 parents 6ca77b2 + 926f51a commit 0eca757
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@
| 76차시 | 2024.09.06 | DFS + 트리 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/150367">표현 가능한 이진트리</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/246
| 77차시 | 2024.09.27 | 구현 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/150366">표 병합</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/247
| 78차시 | 2024.10.06 | 그리디 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/68646">풍선 터뜨리기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/250
| 79차시 | 2024.10.12 | 이분 매칭 | <a href="https://www.acmicpc.net/problem/9576">책 나눠주기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/251
---
38 changes: 38 additions & 0 deletions tgyuuAn/이분 매칭/책 나눠주기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys

def input(): return sys.stdin.readline().rstrip()

T = int(input())
for _ in range(T):
N, M = map(int, input().split())

matches_n = [0 for _ in range(N+1)]
matches_m = [0 for _ in range(M+1)]
want = dict()

for idx in range(1,M+1):
a, b = map(int, input().split())
want[idx] = [idx for idx in range(a, b+1)]

def dfs(now, graph, visited):
visited[now] = True

for _next in graph[now]:
if matches_n[_next] == 0:
matches_n[_next] = now
matches_m[now] = _next
return True

elif visited[matches_n[_next]] == False and dfs(matches_n[_next], graph, visited):
matches_m[now] = _next
return True

return False

answer = 0
for i in range(1,M+1):
visited = [False for _ in range(M+1)]
if(dfs(i, want, visited)):
answer += 1

print(answer)

0 comments on commit 0eca757

Please sign in to comment.