From b66615ff4c7d32f04578161a6e445ea892fe8b6d Mon Sep 17 00:00:00 2001 From: tkdwns414 Date: Mon, 13 Nov 2023 23:56:10 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[BOJ]=20/=20=ED=83=80=EC=9E=84=EB=A8=B8?= =?UTF-8?q?=EC=8B=A0=20/=20Gold4=20/=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week6/[BOJ] 11657 copy.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 week6/[BOJ] 11657 copy.py diff --git a/week6/[BOJ] 11657 copy.py b/week6/[BOJ] 11657 copy.py new file mode 100644 index 0000000..bdf70bc --- /dev/null +++ b/week6/[BOJ] 11657 copy.py @@ -0,0 +1,27 @@ +import sys + +N, M = map(int, sys.stdin.readline().split()) + +road = [] +for _ in range(M): + A, B, C = map(int, sys.stdin.readline().split()) + road.append((A - 1, B - 1, C)) + +res = [int(1e9) for _ in range(N)] +temp = [0 for _ in range(N)] +res[0] = 0 +cycle = False + +for i in range(N): + for j in range(M): + c, n, d = road[j] + if res[c] != int(1e9) and res[n] > res[c] + d: + res[n] = res[c] + d + if i == N - 1: + cycle = True + +if cycle: + print(-1) +else: + for i in range(1, N): + print(res[i] if res[i] != int(1e9) else -1) \ No newline at end of file From 026ffc4d6e00e7f1b156813ce2f3347f3b12cd69 Mon Sep 17 00:00:00 2001 From: tkdwns414 Date: Tue, 14 Nov 2023 15:38:36 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[PRGMS]=20/=20=EC=88=9C=EC=9C=84=20/=20leve?= =?UTF-8?q?l=203=20/=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week6/[PRGMS] 49191.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 week6/[PRGMS] 49191.py diff --git a/week6/[PRGMS] 49191.py b/week6/[PRGMS] 49191.py new file mode 100644 index 0000000..f5ea288 --- /dev/null +++ b/week6/[PRGMS] 49191.py @@ -0,0 +1,22 @@ +def solution(n, results): + answer = 0 + battle_graph = [[0] * n for _ in range(n)] + + for result in results: + battle_graph[result[0] - 1][result[1] - 1] = 1 + battle_graph[result[1] - 1][result[0] - 1] = -1 + + for i in range(n): + for j in range(n): + for k in range(n): + if j == k or battle_graph[j][k] in [1,-1]: + continue + if battle_graph[j][i] == battle_graph[i][k] == 1: + battle_graph[j][k] = 1 + battle_graph[k][j] = battle_graph[i][j] = battle_graph[k][i] = -1 + + for battle in battle_graph: + if battle.count(0) == 1: + answer += 1 + + return answer \ No newline at end of file From c6e3b9e14e1c7e4bfee8c98f8b4c05b7fab9b435 Mon Sep 17 00:00:00 2001 From: tkdwns414 Date: Tue, 14 Nov 2023 16:40:39 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[BOJ]=20/=20=EB=85=B9=EC=83=89=20=EC=98=B7?= =?UTF-8?q?=20=EC=9E=85=EC=9D=80=20=EC=95=A0=EA=B0=80=20=EC=A0=A4=EB=8B=A4?= =?UTF-8?q?=EC=A7=80=3F=20/=20gold=204=20/=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week6/[BOJ] 4485.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 week6/[BOJ] 4485.py diff --git a/week6/[BOJ] 4485.py b/week6/[BOJ] 4485.py new file mode 100644 index 0000000..63262c4 --- /dev/null +++ b/week6/[BOJ] 4485.py @@ -0,0 +1,35 @@ +import heapq + +question_num = 1 +dx = [0, 0, 1, -1] +dy = [1, -1, 0, 0] + +def solve(cave, n): + distance = [[int(1e9)] * n for _ in range(n)] + x, y = 0, 0 + queue = [(cave[x][y], x, y)] + distance[x][y] = cave[x][y] + + while queue: + dist, x, y = heapq.heappop(queue) + if distance[x][y] < dist: + continue + for i in range(4): + nx, ny = x + dx[i], y + dy[i] + if nx < 0 or ny < 0 or nx >= n or ny >= n: + continue + cost = dist + cave[nx][ny] + if cost < distance[nx][ny]: + distance[nx][ny] = cost + heapq.heappush(queue, (cost, nx, ny)) + + return distance[n-1][n-1] + +while True: + n = int(input()) + if n == 0: + break + cave = [list(map(int, input().split())) for _ in range(n)] + + print(f"Problem {question_num}: {solve(cave, n)}") + question_num += 1 \ No newline at end of file