結果

問題 No.1601 With Animals into Institute
ユーザー tentententen
提出日時 2023-07-18 17:55:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,654 ms / 3,000 ms
コード長 3,236 bytes
コンパイル時間 4,144 ms
コンパイル使用メモリ 96,512 KB
実行使用メモリ 110,404 KB
最終ジャッジ日時 2023-10-18 21:17:12
合計ジャッジ時間 31,425 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,592 KB
testcase_01 AC 53 ms
53,600 KB
testcase_02 AC 55 ms
53,584 KB
testcase_03 AC 170 ms
58,244 KB
testcase_04 AC 184 ms
58,116 KB
testcase_05 AC 189 ms
59,456 KB
testcase_06 AC 1,546 ms
104,468 KB
testcase_07 AC 1,616 ms
104,408 KB
testcase_08 AC 1,540 ms
104,500 KB
testcase_09 AC 1,583 ms
105,804 KB
testcase_10 AC 1,609 ms
109,416 KB
testcase_11 AC 1,640 ms
110,404 KB
testcase_12 AC 1,568 ms
109,396 KB
testcase_13 AC 1,624 ms
109,516 KB
testcase_14 AC 1,609 ms
103,904 KB
testcase_15 AC 1,573 ms
108,860 KB
testcase_16 AC 1,584 ms
109,568 KB
testcase_17 AC 1,654 ms
107,908 KB
testcase_18 AC 191 ms
59,716 KB
testcase_19 AC 191 ms
58,400 KB
testcase_20 AC 194 ms
59,144 KB
testcase_21 AC 188 ms
58,440 KB
testcase_22 AC 190 ms
58,560 KB
testcase_23 AC 185 ms
58,620 KB
testcase_24 AC 186 ms
58,512 KB
testcase_25 AC 186 ms
58,700 KB
testcase_26 AC 184 ms
58,592 KB
testcase_27 AC 55 ms
53,580 KB
testcase_28 AC 54 ms
53,580 KB
testcase_29 AC 55 ms
53,572 KB
testcase_30 AC 56 ms
53,592 KB
testcase_31 AC 57 ms
53,580 KB
testcase_32 AC 56 ms
53,588 KB
testcase_33 AC 55 ms
53,576 KB
testcase_34 AC 56 ms
53,576 KB
testcase_35 AC 55 ms
53,584 KB
testcase_36 AC 55 ms
53,580 KB
testcase_37 AC 56 ms
53,576 KB
testcase_38 AC 55 ms
53,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0