diff --git "a/pknujsp/BFS/32-\354\210\250\353\260\224\352\274\255\354\247\210 3.py" "b/pknujsp/BFS/32-\354\210\250\353\260\224\352\274\255\354\247\210 3.py" new file mode 100644 index 00000000..e6aa58f5 --- /dev/null +++ "b/pknujsp/BFS/32-\354\210\250\353\260\224\352\274\255\354\247\210 3.py" @@ -0,0 +1,31 @@ +from sys import * +from collections import * + +n, k = map(int, stdin.readline().strip().split()) + +max_idx = 100001 + +q = deque([(n, 0)]) +visited = [False] * max_idx +visited[n] = True + +while q: + x, cost = q.popleft() + if x == k: + print(cost) + break + + nx = x + x + if nx < max_idx and not visited[nx]: + visited[nx] = True + q.appendleft((nx, cost)) + + nx = x - 1 + if 0 <= nx and not visited[nx]: + visited[nx] = True + q.append((nx, cost + 1)) + + nx = x + 1 + if nx < max_idx and not visited[nx]: + visited[nx] = True + q.append((nx, cost + 1)) diff --git "a/pknujsp/BFS/33-\354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.py" "b/pknujsp/BFS/33-\354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.py" new file mode 100644 index 00000000..34b5a842 --- /dev/null +++ "b/pknujsp/BFS/33-\354\235\264\353\266\204 \352\267\270\353\236\230\355\224\204.py" @@ -0,0 +1,43 @@ +from sys import * +from collections import * + + +def bfs(start): + q = deque([start]) + groups[start] = 1 + + while q: + curr = q.popleft() + visited[curr] = True + + for adj in graph[curr]: + if visited[adj]: + continue + + if not groups[adj]: + groups[adj] = -groups[curr] + q.append(adj) + elif groups[adj] == groups[curr]: + return False + return True + + +for _ in range(int(stdin.readline())): + V, E = map(int, stdin.readline().split()) + graph = [[] for i in range(V + 1)] + + for _ in range(E): + a, b = map(int, stdin.readline().split()) + graph[a].append(b) + graph[b].append(a) + + groups = [0] * (V + 1) + visited = [False] * (V + 1) + result = None + + for i in range(1, V + 1): + if groups[i] == 0 and not bfs(i): + result = 'NO' + break + + print('YES' if not result else result) diff --git a/pknujsp/README.md b/pknujsp/README.md index bdb6a818..9a9e4162 100644 --- a/pknujsp/README.md +++ b/pknujsp/README.md @@ -32,4 +32,6 @@ | 28차시 | 2024.01.16 | 그리디 | [무지의 먹방 라이브](https://school.programmers.co.kr/learn/courses/30/lessons/42891) | [#110](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/110) | | 29차시 | 2024.01.18 | DFS, UNION-FIND | [순열 사이클](https://www.acmicpc.net/problem/10451) | [#112](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/112) | | 30차시 | 2024.01.23 | DP | [ABBC](https://www.acmicpc.net/problem/25381) | [#119](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/119) | -| 31차시 | 2024.01.30 | SORT | [멀티버스 Ⅱ](https://www.acmicpc.net/problem/18869) | [#123](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/123) | \ No newline at end of file +| 31차시 | 2024.01.30 | SORT | [멀티버스 Ⅱ](https://www.acmicpc.net/problem/18869) | [#123](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/123) | +| 32차시 | 2024.02.04 | BFS | [숨바꼭질 3](https://www.acmicpc.net/problem/13549) | [#127](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/127) | +| 33차시 | 2024.02.06 | 큐 | [철로](https://www.acmicpc.net/problem/13334) | [#132](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/132) | \ No newline at end of file diff --git "a/pknujsp/\355\201\220/33-\354\262\240\353\241\234.py" "b/pknujsp/\355\201\220/33-\354\262\240\353\241\234.py" new file mode 100644 index 00000000..acf2420a --- /dev/null +++ "b/pknujsp/\355\201\220/33-\354\262\240\353\241\234.py" @@ -0,0 +1,28 @@ +from sys import * +from heapq import * + +points = [] + +for _ in range(int(stdin.readline().strip())): + h, o = map(int, stdin.readline().strip().split()) + points.append([min(h, o), max(h, o)]) + +points.sort(key=lambda x: x[1]) +D = int(stdin.readline().strip()) + +max_users = 0 +start_points_list = [] + +for start, destination in points: + if start + D < destination: + continue + heappush(start_points_list, start) + + while start_points_list: + if start_points_list[0] + D >= destination: + break + heappop(start_points_list) + + max_users = max(max_users, len(start_points_list)) + +print(max_users)