diff --git "a/_posts/Programmers-\355\225\251\354\212\271\355\203\235\354\213\234\354\232\224\352\270\210.md" "b/_posts/Programmers-\355\225\251\354\212\271\355\203\235\354\213\234\354\232\224\352\270\210.md" deleted file mode 100644 index 7203681dbc12..000000000000 --- "a/_posts/Programmers-\355\225\251\354\212\271\355\203\235\354\213\234\354\232\224\352\270\210.md" +++ /dev/null @@ -1,111 +0,0 @@ -겨우 풀었다... -겪었던 문제들 -- 그래프 구현 방법 낯섬. -- Queue 를 생각 못했음. (그래서 작업을 추가해야 하는 포인트를 쉽게 고안 못했다.) -- Call by reference 문제도 한 번 있었음. -- Node 들의 initial max value 를 너무 작게 줬다. (문제를 잘 읽어보면 대략 얼마나 줘야 할 지 나오는 거였음.) - -```java -package testing; - -import java.util.*; -import java.util.Map.Entry; - -public class Programmers { - public static void main(String[] args) { - - int print = solution( - 6, 4, 6, 2, - new int[][] { - {4, 1, 10}, {3, 5, 24}, {5, 6, 2}, - {3, 1, 41}, {5, 1, 24}, {4, 6, 50}, - {2, 4, 66}, {2, 3, 22}, {1, 6, 25}} - ); - - System.out.println(print); - } - - public static int solution(int n, int s, int a, int b, int[][] fares) { - ArrayList graph = initialize(n, fares); - int[] resultN = dijkstra(graph, n, s); - graph = initialize(n, fares); - int[] resultA = dijkstra(graph, n, a); - graph = initialize(n, fares); - int[] resultB = dijkstra(graph, n, b); - - int answer = Integer.MAX_VALUE; - - for(int i = 0; i < n; i++) { - int trial = resultN[i] + resultA[i] + resultB[i]; - if(trial == 0) continue; - answer = (answer > trial)? trial:answer; - } - - return answer; - } - - private static int[] dijkstra(ArrayList graph, int n, int s) { - int[] result = new int[n]; - Node start = graph.get(s-1); - start.cost = 0; - LinkedList que = new LinkedList(); - que.add(start); - while(!que.isEmpty()) { - Node checkNode = que.pollFirst(); - ArrayList neig = checkNode.neigbours; - int neigSize= neig.size(); - for(int i = 0; i < neigSize; i++) { - if(neig.get(i).setCost(checkNode.cost + - checkNode.weights.get(i))) { - que.add(neig.get(i)); - result[neig.get(i).idx-1] = checkNode.cost + - checkNode.weights.get(i); - } - } - } - return result; - } - - private static ArrayList initialize(int n, int[][] fares) { - ArrayList list = new ArrayList(); - for(int i = 0; i neigbours = new ArrayList<>(); - ArrayList weights = new ArrayList<>(); - Node(int idx){ - this.idx = idx; - } - boolean setCost(int cost) { - if(this.cost > cost) { - this.cost = cost; - return true; - } - return false; - } - void setGraph(Node other, int weight) { - this.neigbours.add(other); - other.neigbours.add(this); - this.weights.add(weight); - other.weights.add(weight); - } - @Override - public String toString() { - return "Node:" + idx + " Cost:" + cost + "\n"; - } -} -``` -