From bd9b2d5f2128f454165cfff454875e8ebb39b908 Mon Sep 17 00:00:00 2001 From: Jeongha Park <162397816+mirupio@users.noreply.github.com> Date: Sat, 25 Jul 2026 14:07:31 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98?= =?UTF-8?q?=EB=A8=B8=EC=8A=A4132266=20-=20=EB=B6=80=EB=8C=80=EB=B3=B5?= =?UTF-8?q?=EA=B7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/programmers/algorithm/dfsbfs/Q132266.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/programmers/algorithm/dfsbfs/Q132266.java diff --git a/src/programmers/algorithm/dfsbfs/Q132266.java b/src/programmers/algorithm/dfsbfs/Q132266.java new file mode 100644 index 0000000..d177bf9 --- /dev/null +++ b/src/programmers/algorithm/dfsbfs/Q132266.java @@ -0,0 +1,55 @@ +package programmers.algorithm.dfsbfs; + +import java.util.*; + +class Q132266 { + static Queue q; + static int[] distance; + static int des; + static List[] graph; + static int ans; + public int[] solution(int n, int[][] roads, int[] sources, int destination) { + int[] answer = new int[sources.length]; + + graph = new ArrayList[n+1]; + for(int i=1;i(); + } + + for(int[] road: roads){ + int from = road[0]; + int to = road[1]; + + graph[from].add(to); + graph[to].add(from); + } + + q = new LinkedList<>(); + distance = new int[n+1]; + Arrays.fill(distance,-1); + + q.offer(destination); + distance[destination] = 0; + + bfs(); + + for(int i=0;i Date: Sat, 25 Jul 2026 16:03:44 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98?= =?UTF-8?q?=EB=A8=B8=EC=8A=A472413=20-=20=ED=95=A9=EC=8A=B9=20=ED=83=9D?= =?UTF-8?q?=EC=8B=9C=20=EC=9A=94=EA=B8=88=20->=20=EB=8B=A4=EC=9D=B5?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../algorithm/dijkstra/Q72413.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/programmers/algorithm/dijkstra/Q72413.java diff --git a/src/programmers/algorithm/dijkstra/Q72413.java b/src/programmers/algorithm/dijkstra/Q72413.java new file mode 100644 index 0000000..940b507 --- /dev/null +++ b/src/programmers/algorithm/dijkstra/Q72413.java @@ -0,0 +1,72 @@ +package programmers.algorithm.dijkstra; + +import java.util.*; + +class Q72413 { + static PriorityQueue pq; + static List[] graph; + static int[] distance; + public int solution(int n, int s, int a, int b, int[][] fares) { + graph = new ArrayList[n+1]; + for(int i=0;i(); + } + for(int[] fare:fares){ + int from = fare[0]; + int to = fare[1]; + int cost = fare[2]; + + graph[from].add(new int[]{to,cost}); + graph[to].add(new int[]{from,cost}); + } + + int answer = Integer.MAX_VALUE; + + // S -> K + K -> A + K -> B + // S -> K + A -> K + B -> K + + int[] disS = dijkstra(n,s); // S 시작 + int[] disA = dijkstra(n,a); // A 시작 + int[] disB = dijkstra(n,b); // B 시작 + + for(int k=1;k pq = + new PriorityQueue<>((x, y) -> Integer.compare(x[1], y[1])); + + distance[start] = 0; + pq.offer(new int[]{start, 0}); + + while(!pq.isEmpty()){ + int[] cur = pq.poll(); + int now = cur[0]; + int cost = cur[1]; + + if(cost > distance[now]){ + continue; + } + + for(int[] nexts : graph[now]){ + int next = nexts[0]; + int nextCost = nexts[1]; + + if(distance[next] > distance[now] + nextCost){ + distance[next] = distance[now] + nextCost; + + pq.offer(new int[]{next,distance[next]}); + } + } + } + return distance; + } + +} \ No newline at end of file From 97951f6745de732dc7fa67d62e093f86a5005157 Mon Sep 17 00:00:00 2001 From: Jeongha Park <162397816+mirupio@users.noreply.github.com> Date: Sat, 25 Jul 2026 16:31:42 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98?= =?UTF-8?q?=EB=A8=B8=EC=8A=A472413=20-=20=ED=95=A9=EC=8A=B9=20=ED=83=9D?= =?UTF-8?q?=EC=8B=9C=20=EC=9A=94=EA=B8=88=20->=20=ED=94=8C=EB=A1=9C?= =?UTF-8?q?=EC=9D=B4=EB=93=9C=20=EC=9B=8C=EC=85=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../algorithm/floydwarshall/Q72413.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/programmers/algorithm/floydwarshall/Q72413.java diff --git a/src/programmers/algorithm/floydwarshall/Q72413.java b/src/programmers/algorithm/floydwarshall/Q72413.java new file mode 100644 index 0000000..4784be5 --- /dev/null +++ b/src/programmers/algorithm/floydwarshall/Q72413.java @@ -0,0 +1,41 @@ +package programmers.algorithm.floydwarshall; + +import java.util.*; + +class Q72413 { + public int solution(int n, int s, int a, int b, int[][] fares) { + int INF = 1000000000; + int[][] dp = new int[n+1][n+1]; + for(int i=1;i Date: Sat, 25 Jul 2026 22:48:05 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98?= =?UTF-8?q?=EB=A8=B8=EC=8A=A460061=20-=20=EA=B8=B0=EB=91=A5=EA=B3=BC=20?= =?UTF-8?q?=EB=B3=B4=20=EC=84=A4=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../algorithm/implementation/Q60061.java | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/programmers/algorithm/implementation/Q60061.java diff --git a/src/programmers/algorithm/implementation/Q60061.java b/src/programmers/algorithm/implementation/Q60061.java new file mode 100644 index 0000000..c643f60 --- /dev/null +++ b/src/programmers/algorithm/implementation/Q60061.java @@ -0,0 +1,97 @@ +package programmers.algorithm.implementation; + +import java.util.*; + +class Q60061 { + static int N; + static boolean[][] pillar; // x,y에 기둥 있는지 + static boolean[][] bar; // x,y에 보 있는지 + public int[][] solution(int n, int[][] build_frames) { + N = n; + pillar = new boolean[n+1][n+1]; + bar = new boolean[n+1][n+1]; + + // 적용했을 때 조건 만족하면 실행 + for(int[] build_frame:build_frames){ + int x = build_frame[0]; + int y = build_frame[1]; + int a = build_frame[2]; + int b = build_frame[3]; + + // 기둥 삭제 + if(b == 0 && a == 0){ + pillar[x][y] = false; + if(!isValid()){ + pillar[x][y] = true; + } + } + // 기둥 설치 + else if(b == 1 && a == 0){ + pillar[x][y] = true; + if(!isValid()){ + pillar[x][y] = false; + } + } + // 보 삭제 + else if(b == 0 && a == 1){ + bar[x][y] = false; + if(!isValid()){ + bar[x][y] = true; + } + } + // 보 설치 + else if(b == 1 && a == 1){ + bar[x][y] = true; + if(!isValid()){ + bar[x][y] = false; + } + } + + } + + List result = new ArrayList<>(); + for(int i=0;i0 && bar[x-1][y]) + || (y>0 && pillar[x][y-1]))){ + return false; + } + } + + // 보 + if(bar[x][y]){ + // 한쪽 끝이 기둥 위 or 양쪽 끝이 다른 보와 연결 + if (!((y > 0 && pillar[x][y - 1]) + || (x 0 && pillar[x + 1][y - 1]) + || (x > 0 && x