diff --git "a/4\354\243\274\354\260\250/\352\260\200\354\236\245\355\201\260\354\210\230/\352\260\200\354\236\245\355\201\260\354\210\230_\354\235\264\354\243\274\355\230\201.java" "b/4\354\243\274\354\260\250/\352\260\200\354\236\245\355\201\260\354\210\230/\352\260\200\354\236\245\355\201\260\354\210\230_\354\235\264\354\243\274\355\230\201.java" new file mode 100644 index 0000000..fb99641 --- /dev/null +++ "b/4\354\243\274\354\260\250/\352\260\200\354\236\245\355\201\260\354\210\230/\352\260\200\354\236\245\355\201\260\354\210\230_\354\235\264\354\243\274\355\230\201.java" @@ -0,0 +1,39 @@ +/* +어떤 것 먼저? + +*/ +import java.util.*; +class Solution { + public static class StringNum implements Comparable { + + String num; + + public StringNum(String num){ + this.num = num; + } + + @Override + public int compareTo(StringNum o1){ + return -1 * (this.num + o1.num).compareTo(o1.num + this.num); + } + + } + + public String solution(int[] numbers) { + String answer = ""; + + StringNum[] nums = new StringNum[numbers.length]; + + for(int i = 0; i < nums.length; i++) { + nums[i] = new StringNum(String.valueOf(numbers[i])); + } + + Arrays.sort(nums); + + if(nums[0].num.equals("0")) return "0"; + + for(int i=0; i q = new ArrayDeque(); + visited[arr[0].r][arr[0].c][arr[1].r][arr[1].c] = true; + q.offer(arr); + + int turn = 0; + while(turn < 10 && !q.isEmpty()) { + + int qSize = q.size(); + turn++; + for (int k=0; k=N || c>=M; + } + +} diff --git "a/4\354\243\274\354\260\250/\355\225\251\353\246\254\354\240\201\354\235\270\354\235\264\353\217\231\352\262\275\353\241\234/\355\225\251\353\246\254\354\240\201\354\235\270\354\235\264\353\217\231\352\262\275\353\241\234_\354\235\264\354\243\274\355\230\201.java" "b/4\354\243\274\354\260\250/\355\225\251\353\246\254\354\240\201\354\235\270\354\235\264\353\217\231\352\262\275\353\241\234/\355\225\251\353\246\254\354\240\201\354\235\270\354\235\264\353\217\231\352\262\275\353\241\234_\354\235\264\354\243\274\355\230\201.java" new file mode 100644 index 0000000..80a51de --- /dev/null +++ "b/4\354\243\274\354\260\250/\355\225\251\353\246\254\354\240\201\354\235\270\354\235\264\353\217\231\352\262\275\353\241\234/\355\225\251\353\246\254\354\240\201\354\235\270\354\235\264\353\217\231\352\262\275\353\241\234_\354\235\264\354\243\274\355\230\201.java" @@ -0,0 +1,68 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class Main { + static final int MAX = 1001; + static final int INF = Integer.MAX_VALUE; + static ArrayList[] adj = new ArrayList[MAX]; + static int[] dist = new int[MAX]; + static int[] dp = new int[MAX]; + + static class Pair implements Comparable { + int cost, vertex; + public Pair(int cost, int vertex) { + this.cost = cost; + this.vertex = vertex; + } + public int compareTo(Pair other) { + return Integer.compare(this.cost, other.cost); + } + } + + public static void dijkstra(int start) { + Arrays.fill(dist, INF); + PriorityQueue pq = new PriorityQueue<>(); + dist[start] = 0; + pq.add(new Pair(0, start)); + while (!pq.isEmpty()) { + Pair top = pq.poll(); + int curCost = top.cost; + int cur = top.vertex; + if (dist[cur] != curCost) continue; + for (Pair edge : adj[cur]) { + int nextCost = edge.cost; + int next = edge.vertex; + if (dist[next] > curCost + nextCost) { + dist[next] = curCost + nextCost; + pq.add(new Pair(dist[next], next)); + } + if (dist[cur] > dist[next]) { + dp[cur] += dp[next]; + } + } + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + for (int i = 0; i < MAX; i++) { + adj[i] = new ArrayList<>(); + } + dp[2] = 1; + while (m-- > 0) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + adj[a].add(new Pair(c, b)); + adj[b].add(new Pair(c, a)); + } + dijkstra(2); + System.out.println(dp[1]); + } +}