Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

79-tgyuuAn #251

Merged
merged 2 commits into from
Nov 11, 2024
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
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
---
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)