diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 98e2e47..eef1313 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -85,4 +85,5 @@ | 76차시 | 2024.09.06 | DFS + 트리 | 표현 가능한 이진트리 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/246 | 77차시 | 2024.09.27 | 구현 | 표 병합 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/247 | 78차시 | 2024.10.06 | 그리디 | 풍선 터뜨리기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/250 +| 79차시 | 2024.10.12 | 이분 매칭 | 책 나눠주기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/251 --- diff --git "a/tgyuuAn/\354\235\264\353\266\204 \353\247\244\354\271\255/\354\261\205 \353\202\230\353\210\240\354\243\274\352\270\260.py" "b/tgyuuAn/\354\235\264\353\266\204 \353\247\244\354\271\255/\354\261\205 \353\202\230\353\210\240\354\243\274\352\270\260.py" new file mode 100644 index 0000000..6f078fa --- /dev/null +++ "b/tgyuuAn/\354\235\264\353\266\204 \353\247\244\354\271\255/\354\261\205 \353\202\230\353\210\240\354\243\274\352\270\260.py" @@ -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) \ No newline at end of file