From 6b1946ef57a689a12aac02382d0b787b11b24e0e Mon Sep 17 00:00:00 2001 From: tngur1101 Date: Mon, 25 Sep 2023 00:19:03 +0900 Subject: [PATCH 1/3] =?UTF-8?q?BOJ=5F1507=5F=EA=B6=81=EA=B8=88=ED=95=9C?= =?UTF-8?q?=EB=AF=BC=ED=98=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\225\234\353\257\274\355\230\270.java" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "kimsuhyeok/BOJ_1507_\352\266\201\352\270\210\355\225\234\353\257\274\355\230\270.java" diff --git "a/kimsuhyeok/BOJ_1507_\352\266\201\352\270\210\355\225\234\353\257\274\355\230\270.java" "b/kimsuhyeok/BOJ_1507_\352\266\201\352\270\210\355\225\234\353\257\274\355\230\270.java" new file mode 100644 index 0000000..8011987 --- /dev/null +++ "b/kimsuhyeok/BOJ_1507_\352\266\201\352\270\210\355\225\234\353\257\274\355\230\270.java" @@ -0,0 +1,62 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +/** + * 1. 이미 최단거리임 + * 그렇다면 우리는 플로이드 워셜 알고리즘을 수행한 배열을 이용해서 플로이드 워셜 알고리즘 수행 전 배열을 찾아야 함 + * + */ +public class Main { + + static int N; + static int[][] map; + static int[][] copy; + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + map = new int[N][N]; + copy = new int[N][N]; + + for(int i=0;i map[j][i] + map[i][k]){ + System.out.println(-1); + System.exit(0); + } + } + } + } + + int answer = 0; + + for(int i=0;i Date: Mon, 25 Sep 2023 00:19:34 +0900 Subject: [PATCH 2/3] =?UTF-8?q?BOJ=5F11779=5F=EC=B5=9C=EC=86=8C=EB=B9=84?= =?UTF-8?q?=EC=9A=A9=EA=B5=AC=ED=95=98=EA=B8=B02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\265\254\355\225\230\352\270\2602.java" | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 "kimsuhyeok/BOJ_11779_\354\265\234\354\206\214\353\271\204\354\232\251\352\265\254\355\225\230\352\270\2602.java" diff --git "a/kimsuhyeok/BOJ_11779_\354\265\234\354\206\214\353\271\204\354\232\251\352\265\254\355\225\230\352\270\2602.java" "b/kimsuhyeok/BOJ_11779_\354\265\234\354\206\214\353\271\204\354\232\251\352\265\254\355\225\230\352\270\2602.java" new file mode 100644 index 0000000..ba7705c --- /dev/null +++ "b/kimsuhyeok/BOJ_11779_\354\265\234\354\206\214\353\271\204\354\232\251\352\265\254\355\225\230\352\270\2602.java" @@ -0,0 +1,110 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +/** + * 도시의 개수 : N + * 버스의 개수 : M + * + * + */ +public class Main { + + static class Node implements Comparable{ + int to; + int weight; + public Node(int to, int weight){ + this.to = to; + this.weight = weight; + } + + @Override + public int compareTo(Node o) { + return this.weight-o.weight; + } + } + static int N,M; + static int[] dist; //거리 배열 + static int[] prev; //직전 도시 저장할 배열 + static boolean[] visited; + static List[] list; + static int start, end; + static final int INF = 1000000001; + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + M = Integer.parseInt(br.readLine()); + + list = new ArrayList[N+1]; + for(int i=1;i<=N;i++){ + list[i] = new ArrayList<>(); + } + + for(int i=0;i routes = new ArrayList<>(); + + //역추적 + int trace = end; + + while(trace!=0){ + routes.add(trace); + trace = prev[trace]; + } + + System.out.println(routes.size()); + + for(int i= routes.size()-1;i>=0;i--){ + System.out.print(routes.get(i)+" "); + } + + } + + public static void dijkstra(){ + PriorityQueue queue = new PriorityQueue<>(); + queue.offer(new Node(start,0)); + dist[start] = 0; + prev[start] = 0; + + while(!queue.isEmpty()){ + Node cur = queue.poll(); + + if(!visited[cur.to]){ + visited[cur.to] = true; + } + else continue; + + for(int i=0;idist[cur.to]+next.weight){ + dist[next.to] = dist[cur.to]+next.weight; + queue.offer(new Node(next.to, dist[next.to])); + prev[next.to] = cur.to; + } + } + } + } + +} From d3d698f6ef16a8a912c92c5313dfdbecdf2e7193 Mon Sep 17 00:00:00 2001 From: tngur1101 Date: Mon, 25 Sep 2023 00:20:32 +0900 Subject: [PATCH 3/3] BOJ_11437_LCA --- kimsuhyeok/BOJ_11437_LCA.java | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 kimsuhyeok/BOJ_11437_LCA.java diff --git a/kimsuhyeok/BOJ_11437_LCA.java b/kimsuhyeok/BOJ_11437_LCA.java new file mode 100644 index 0000000..8e4414b --- /dev/null +++ b/kimsuhyeok/BOJ_11437_LCA.java @@ -0,0 +1,82 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +/** + * 세그먼트 트리 + * 연속된 구간의 데이터의 합을 가장 빠르고 간단하게 구할 수 있는 트리 + * 루트 노드에 모든 원소를 더한 값이 들어가는 방식 + */ +public class Main { + + static List[] list; + static int[] parent, depth; + static int N,M; + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + N = Integer.parseInt(br.readLine()); + + parent = new int[N+1]; + depth = new int[N+1]; + list = new ArrayList[N+1]; + for(int i=1;i<=N;i++){ + list[i] = new ArrayList<>(); + } + + for(int i=0;i bh){ + a = parent[a]; + ah--; + } + + while(bh>ah){ + b = parent[b]; + bh--; + } + + while(a!=b){ + a = parent[a]; + b = parent[b]; + } + return a; + } + +}