다익스트라 알고리즘
private static void dijkstra(int s, int[] dist) { for (int i = 1; i < dist.length; i++) dist[i] = Integer.MAX_VALUE;
PriorityQueue<Node> pq = new PriorityQueue<Node>(); pq.add(new Node(s, 0)); dist[s] = 0; Node nd; while (!pq.isEmpty()) { nd = pq.poll(); if(list[nd.e]==null) continue; for (Node node : list[nd.e]) { if(dist[node.e] > dist[nd.e] + node.c) { dist[node.e] = dist[nd.e] + node.c; pq.add(new Node(node.e, dist[nd.e]+node.c)); } } } } |