結果

問題 No.1601 With Animals into Institute
ユーザー tentententen
提出日時 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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
37,372 KB
testcase_01 AC 52 ms
37,232 KB
testcase_02 AC 53 ms
37,388 KB
testcase_03 AC 169 ms
43,184 KB
testcase_04 AC 162 ms
42,408 KB
testcase_05 AC 166 ms
42,536 KB
testcase_06 AC 1,283 ms
92,496 KB
testcase_07 AC 1,296 ms
91,708 KB
testcase_08 AC 1,299 ms
91,384 KB
testcase_09 AC 1,382 ms
95,372 KB
testcase_10 AC 1,369 ms
96,264 KB
testcase_11 AC 1,320 ms
95,748 KB
testcase_12 AC 1,350 ms
95,280 KB
testcase_13 AC 1,370 ms
92,452 KB
testcase_14 AC 1,356 ms
91,640 KB
testcase_15 AC 1,322 ms
95,188 KB
testcase_16 AC 1,433 ms
91,636 KB
testcase_17 AC 1,327 ms
95,052 KB
testcase_18 AC 149 ms
42,664 KB
testcase_19 AC 169 ms
43,680 KB
testcase_20 AC 162 ms
42,280 KB
testcase_21 AC 167 ms
42,600 KB
testcase_22 AC 170 ms
42,576 KB
testcase_23 AC 167 ms
42,256 KB
testcase_24 AC 157 ms
42,344 KB
testcase_25 AC 167 ms
42,424 KB
testcase_26 AC 166 ms
42,796 KB
testcase_27 AC 50 ms
37,248 KB
testcase_28 AC 49 ms
37,416 KB
testcase_29 AC 50 ms
37,104 KB
testcase_30 AC 50 ms
37,232 KB
testcase_31 AC 50 ms
37,220 KB
testcase_32 AC 52 ms
37,132 KB
testcase_33 AC 52 ms
37,128 KB
testcase_34 AC 52 ms
37,308 KB
testcase_35 AC 51 ms
37,260 KB
testcase_36 AC 52 ms
36,868 KB
testcase_37 AC 51 ms
37,288 KB
testcase_38 AC 52 ms
37,232 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