From 18960f41247121240fe8e38a47ef6708eab3f67e Mon Sep 17 00:00:00 2001 From: jeeminimini Date: Mon, 20 Nov 2023 20:37:36 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat=20:=20=EB=B6=81=EC=AA=BD=EB=82=98?= =?UTF-8?q?=EB=9D=BC=EC=9D=98=20=EB=8F=84=EB=A1=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\235\230 \353\217\204\353\241\234.py" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "src/main/kotlin/jimin/50week/\353\266\201\354\252\275\353\202\230\353\235\274\354\235\230 \353\217\204\353\241\234.py" diff --git "a/src/main/kotlin/jimin/50week/\353\266\201\354\252\275\353\202\230\353\235\274\354\235\230 \353\217\204\353\241\234.py" "b/src/main/kotlin/jimin/50week/\353\266\201\354\252\275\353\202\230\353\235\274\354\235\230 \353\217\204\353\241\234.py" new file mode 100644 index 00000000..f90ac54a --- /dev/null +++ "b/src/main/kotlin/jimin/50week/\353\266\201\354\252\275\353\202\230\353\235\274\354\235\230 \353\217\204\353\241\234.py" @@ -0,0 +1,40 @@ +''' + +https://dodobow.tistory.com/35 + +근데 왜 1과 1로 돌고 난 후의 max만 확인하면 될까? +''' + +import sys +from collections import deque + +roads = [[] for _ in range(10_001)] +while True: + try: + a, b, c = map(int, sys.stdin.readline().split()) + roads[a].append([b, c]) + roads[b].append([a, c]) + except: + break + + +def bfs(start): + queue = deque([start]) + + visited[start] = 0 + + while queue: + now = queue.popleft() + + for i, w in roads[now]: + if visited[i] == -1: + visited[i] = visited[now] + w + queue.append(i) + + +visited = [-1 for _ in range(10_001)] +bfs(1) +s = visited.index(max(visited)) +visited = [-1 for _ in range(10_001)] +bfs(s) +print(max(visited)) From dc3095d3ce47d62bf1bced19e00efe9a501dc3ec Mon Sep 17 00:00:00 2001 From: jeeminimini Date: Mon, 20 Nov 2023 20:37:52 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat=20:=20=EC=88=AB=EC=9E=90=EA=B3=A0?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20\352\263\240\353\245\264\352\270\260.py" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "src/main/kotlin/jimin/50week/\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.py" diff --git "a/src/main/kotlin/jimin/50week/\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.py" "b/src/main/kotlin/jimin/50week/\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.py" new file mode 100644 index 00000000..6776da1a --- /dev/null +++ "b/src/main/kotlin/jimin/50week/\354\210\253\354\236\220\352\263\240\353\245\264\352\270\260.py" @@ -0,0 +1,36 @@ +''' +처음에는 그냥 dfs로 했더니 시간초과났다 + +사이클을 도는 친구를 찾아야한다.. +https://velog.io/@deannn/BOJ-%EB%B0%B1%EC%A4%80-2668%EB%B2%88-%EC%88%AB%EC%9E%90%EA%B3%A0%EB%A5%B4%EA%B8%B0-Python +참고 +''' + +import sys +n = int(sys.stdin.readline()) +numbers = [0] +for i in range(n): + numbers.append(int(sys.stdin.readline())) + +answer = set() + + +def dfs(first, second, now): + first.add(now) + second.add(numbers[now]) + if numbers[now] in first: + if first == second: + answer.update(first) + return + return + return dfs(first, second, numbers[now]) + + +for i in range(1, n + 1): + if i not in answer: + dfs(set(), set(), i) + +print(len(answer)) +for num in sorted(list(answer)): + print(num) + From 8dff123b5d114f8361f7bdcf4305f6a96501ae4e Mon Sep 17 00:00:00 2001 From: jeeminimini Date: Mon, 20 Nov 2023 20:37:59 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat=20:=20=EC=97=B0=EA=B5=AC=EC=86=8C2=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\227\260\352\265\254\354\206\2142.py" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "src/main/kotlin/jimin/50week/\354\227\260\352\265\254\354\206\2142.py" diff --git "a/src/main/kotlin/jimin/50week/\354\227\260\352\265\254\354\206\2142.py" "b/src/main/kotlin/jimin/50week/\354\227\260\352\265\254\354\206\2142.py" new file mode 100644 index 00000000..5b1e2ce8 --- /dev/null +++ "b/src/main/kotlin/jimin/50week/\354\227\260\352\265\254\354\206\2142.py" @@ -0,0 +1,70 @@ +import sys +from collections import deque +from itertools import combinations + +n, m = map(int, sys.stdin.readline().split()) + +ground = [] +for i in range(n): + ground.append(list(map(int, sys.stdin.readline().split()))) + +mini = 100_000_000 + + +def bfs(viruses): + global n, mini, ground + queue = deque(viruses) + + visited = [[0 for _ in range(n)] for _ in range(n)] + for i in range(n): + for j in range(n): + if ground[i][j] == 1: + visited[i][j] = -1 + + for x, y in viruses: + visited[x][y] = 1 + + dx = [0, 0, -1, 1] + dy = [1, -1, 0, 0] + + while queue: + nx, ny = queue.popleft() + + for i in range(4): + if 0 <= nx + dx[i] < n and 0 <= ny + dy[i] < n and visited[nx + dx[i]][ny + dy[i]] == 0: + queue.append([nx + dx[i], ny + dy[i]]) + visited[nx + dx[i]][ny + dy[i]] = visited[nx][ny] + 1 + + can = True + for i in range(n): + for j in range(n): + if visited[i][j] == 0: + can = False + break + + if not can: + return + + maxi = 0 + for v in visited: + maxi = max(maxi, max(v)) + + mini = min(maxi - 1, mini) + + +possible = [] +for i in range(n): + for j in range(n): + if ground[i][j] == 2: + possible.append([i, j]) + + +for combi in combinations(possible, m): + bfs(list(combi)) + +if mini == 100_000_000: + print(-1) +else: + print(mini) + +