結果
| 問題 | No.1601 With Animals into Institute | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2023-07-18 17:55:33 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,433 ms / 3,000 ms | 
| コード長 | 3,236 bytes | 
| コンパイル時間 | 3,841 ms | 
| コンパイル使用メモリ | 84,796 KB | 
| 実行使用メモリ | 96,264 KB | 
| 最終ジャッジ日時 | 2024-09-18 17:19:27 | 
| 合計ジャッジ時間 | 26,594 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 36 | 
ソースコード
import java.io.*;
import java.util.*;
import java.util.stream.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<ArrayList<Path>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int c = sc.nextInt();
            int x = sc.nextInt();
            graph.get(a).add(new Path(b, c, x));
            graph.get(b).add(new Path(a, c, x));
        }
        PriorityQueue<Path> queue = new PriorityQueue<>();
        queue.add(new Path(n - 1, 0, 0));
        long[][] costs = new long[n][2];
        for (long[] arr : costs) {
            Arrays.fill(arr, Long.MAX_VALUE);
        }
        while (queue.size() > 0) {
            Path p = queue.poll();
            if (costs[p.idx][p.ani] <= p.value) {
                continue;
            }
            costs[p.idx][p.ani] = p.value;
            for (Path x : graph.get(p.idx)) {
                queue.add(new Path(x.idx, p.value + x.value, p.ani + x.ani));
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n - 1; i++) {
            sb.append(costs[i][1]).append("\n");
        }
        System.out.print(sb);
    }
    
    static class Path implements Comparable<Path> {
        int idx;
        long value;
        int ani;
        
        public Path(int idx, long value, int ani) {
            this.idx = idx;
            this.value = value;
            this.ani = Math.min(ani, 1);
        }
        
        public int compareTo(Path another) {
            if (value == another.value) {
                return 0;
            } else if (value < another.value) {
                return -1;
            } else {
                return 1;
            }
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
            
            
            
        