Submission #74603124


Source Code Expand

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;

@SuppressWarnings("DuplicatedCode")
public class Main {
    static int MAX_STRING_LENGTH = (int) 1e6; // 字符串最大长度
    static int MAX_DIGIT_LENGTH = (int) 1e6; // 数位最大长度
    static int MOD7 = (int) 1e9 + 7, MOD8 = 80112002, MOD9 = 998244353, inf = Integer.MAX_VALUE;

    /***** 检查 T *****/
    static class Solution {

        void solve() {
            int n = io.nextInt(), m = io.nextInt();
            List<int[]>[] g = new List[n];
            Arrays.setAll(g, i -> new ArrayList<>());
            for (int i = 0; i < m; i++) {
                int x = io.nextInt() - 1, y = io.nextInt() - 1, w = io.nextInt();
                g[x].add(new int[] {y, w});
            }
            PriorityQueue<long[]> pq = new PriorityQueue<>((a, b) -> Long.compare(a[1], b[1]));
            long[] dis = new long[n];
            Arrays.fill(dis, Long.MAX_VALUE);
            dis[0] = 0;
            pq.offer(new long[] {0, 0});
            while (!pq.isEmpty()) {
                long[] p = pq.poll();
                int x = (int) p[0];
                long d = p[1];
                if (x == n - 1) {
                    io.println(d);
                    return;
                }
                if (dis[x] < d) continue;
                for (int[] q : g[x]) {
                    int y = q[0], w = q[1];
                    if (dis[y] > d + w) {
                        dis[y] = d + w;
                        pq.offer(new long[] {y, dis[y]});
                    }
                }
            }
        }


    }


    public static void main(String[] args) {
        io = new IO();
        int T = 1;
        // T = io.nextInt();
        for (; T > 0; T--) {
            new Solution().solve();
        }
        io.close();
    }

    static IO io;
    static class IO {
        BufferedInputStream bis = new BufferedInputStream(System.in);
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));

        int nextInt() {
            return (int) nextLong();
        }

        long nextLong() {
            try {
                long sign = 1, x = 0;
                int c = bis.read();
                while (c < '0' || c > '9') {
                    if (c == '-') sign = -1;
                    c = bis.read();
                }
                while (c >= '0' && c <= '9') {
                    x = x * 10 + (c - '0');
                    c = bis.read();
                }
                return sign * x;
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage());
            }
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                try {
                    int sign = 1, x = 0;
                    int c = bis.read();
                    while (c < '0' || c > '9') {
                        if (c == '-') sign = -1;
                        c = bis.read();
                    }
                    while (c >= '0' && c <= '9') {
                        x = x * 10 + (c - '0');
                        c = bis.read();
                    }
                    a[i] = sign * x;
                } catch (IOException e) {
                    throw new RuntimeException(e.getMessage());
                }
            }
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                try {
                    long sign = 1, x = 0;
                    int c = bis.read();
                    while (c < '0' || c > '9') {
                        if (c == '-') sign = -1;
                        c = bis.read();
                    }
                    while (c >= '0' && c <= '9') {
                        x = x * 10 + (c - '0');
                        c = bis.read();
                    }
                    a[i] = sign * x;
                } catch (IOException e) {
                    throw new RuntimeException(e.getMessage());
                }
            }
            return a;
        }

        int[] nextDigitArray(int n) {
            try {
                int[] a = new int[n];
                int x = bis.read();
                while (ignore(x)) {
                    x = bis.read();
                }
                int i = 0;
                while (!ignore(x)) {
                    a[i++] = x - '0';
                    x = bis.read();
                }
                return a;
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }

        private int[] DIGIT_ARRAY;

        int[] nextDigitArray() {
            try {
                if (DIGIT_ARRAY == null) {
                    DIGIT_ARRAY = new int[MAX_DIGIT_LENGTH];
                }
                int x = bis.read();
                while (ignore(x)) {
                    x = bis.read();
                }
                int m = 0;
                while (!ignore(x)) {
                    DIGIT_ARRAY[m++] = x - '0';
                    x = bis.read();
                }
                int[] a = new int[m];
                System.arraycopy(DIGIT_ARRAY, 0, a, 0, m);
                return a;
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }

        char nextChar() {
            try {
                int x = bis.read();
                while (ignore(x)) {
                    x = bis.read();
                }
                return (char) x;
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }

        String[] nextStringArray(int n) {
            String[] a = new String[n];
            for (int i = 0; i < n; i++) {
                try {
                    if (CHAR_ARRAY == null) {
                        CHAR_ARRAY = new char[MAX_STRING_LENGTH];
                    }
                    int x = bis.read();
                    while (ignore(x)) {
                        x = bis.read();
                    }
                    int m = 0;
                    while (x != ' ' && x != ',' && !ignore(x)) {
                        CHAR_ARRAY[m++] = (char) x;
                        x = bis.read();
                    }
                    a[i] = new String(CHAR_ARRAY, 0, m);
                } catch (IOException e) {
                    throw new RuntimeException(e.getMessage());
                }
            }
            return a;
        }

        private char[] CHAR_ARRAY;

        char[] nextCharArray(boolean line) {
            try {
                if (CHAR_ARRAY == null) {
                    CHAR_ARRAY = new char[MAX_STRING_LENGTH];
                }
                int x = bis.read();
                while (ignore(x)) {
                    x = bis.read();
                }
                int m = 0;
                while (line ? (x == ' ' || x == ',' || !ignore(x)) : !ignore(x)) {
                    CHAR_ARRAY[m++] = (char) x;
                    x = bis.read();
                }
                char[] a = new char[m];
                System.arraycopy(CHAR_ARRAY, 0, a, 0, m);
                return a;
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }

        char[] nextCharArray(int n) {
            try {
                char[] a = new char[n];
                int x = bis.read();
                while (ignore(x)) {
                    x = bis.read();
                }
                int i = 0;
                while (!ignore(x)) {
                    a[i++] = (char) x;
                    x = bis.read();
                }
                return a;
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }

        private boolean ignore(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        String nextString(boolean line) {
            return new String(nextCharArray(line));
        }

        String nextString() {
            return nextString(false);
        }

        boolean nextBoolean() {
            return "true".equalsIgnoreCase(nextString());
        }

        double nextDouble() {
            return Double.parseDouble(nextString());
        }

        void println(Object obj) {
            print(obj);
            print("\n");
        }

        void println() {
            print('\n');
        }

        void print(Object obj) {
            pw.print(obj);
        }

        void printf(String format, Object... obj) {
            pw.printf(format, obj);
        }

        void close() {
            try {
                if (bis != null) bis.close();
                if (pw != null) {
                    pw.flush();
                    pw.close();
                }
                bis = null;
                pw = null;
            } catch (Exception ignore) {
            }
        }
    }
}

Submission Info

Submission Time
Task D - Fastest Delivery Route
User gaoyuliang
Language Java24 (OpenJDK 24.0.2)
Score 400
Code Size 9571 Byte
Status AC
Exec Time 300 ms
Memory 73896 KiB

Compile Error

Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 85
Set Name Test Cases
Sample sample01.txt, sample02.txt, sample03.txt
All sample01.txt, sample02.txt, sample03.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in46.txt, in47.txt, in48.txt, in49.txt, in50.txt, in51.txt, in52.txt, in53.txt, in54.txt, in55.txt, in56.txt, in57.txt, in58.txt, in59.txt, in60.txt, in61.txt, in62.txt, in63.txt, in64.txt, in65.txt, in66.txt, in67.txt, in68.txt, in69.txt, in70.txt, in71.txt, in72.txt, in73.txt, in74.txt, in75.txt, in76.txt, in77.txt, in78.txt, in79.txt, in80.txt, in81.txt, in82.txt
Case Name Status Exec Time Memory
in01.txt AC 51 ms 38460 KiB
in02.txt AC 52 ms 39240 KiB
in03.txt AC 68 ms 39560 KiB
in04.txt AC 57 ms 39656 KiB
in05.txt AC 47 ms 38248 KiB
in06.txt AC 48 ms 38656 KiB
in07.txt AC 171 ms 69532 KiB
in08.txt AC 53 ms 38920 KiB
in09.txt AC 199 ms 56356 KiB
in10.txt AC 70 ms 39924 KiB
in11.txt AC 203 ms 56672 KiB
in12.txt AC 231 ms 57792 KiB
in13.txt AC 186 ms 69844 KiB
in14.txt AC 128 ms 51204 KiB
in15.txt AC 196 ms 54376 KiB
in16.txt AC 192 ms 69744 KiB
in17.txt AC 164 ms 50560 KiB
in18.txt AC 239 ms 73652 KiB
in19.txt AC 281 ms 73896 KiB
in20.txt AC 168 ms 50628 KiB
in21.txt AC 210 ms 72880 KiB
in22.txt AC 251 ms 72756 KiB
in23.txt AC 174 ms 56468 KiB
in24.txt AC 192 ms 56588 KiB
in25.txt AC 182 ms 57272 KiB
in26.txt AC 256 ms 73532 KiB
in27.txt AC 48 ms 38688 KiB
in28.txt AC 163 ms 68544 KiB
in29.txt AC 47 ms 38292 KiB
in30.txt AC 47 ms 38768 KiB
in31.txt AC 47 ms 38632 KiB
in32.txt AC 47 ms 38672 KiB
in33.txt AC 47 ms 38644 KiB
in34.txt AC 47 ms 38512 KiB
in35.txt AC 300 ms 73652 KiB
in36.txt AC 274 ms 72268 KiB
in37.txt AC 47 ms 38648 KiB
in38.txt AC 47 ms 38748 KiB
in39.txt AC 50 ms 38448 KiB
in40.txt AC 51 ms 38816 KiB
in41.txt AC 55 ms 39288 KiB
in42.txt AC 56 ms 39764 KiB
in43.txt AC 47 ms 38476 KiB
in44.txt AC 47 ms 38604 KiB
in45.txt AC 47 ms 38560 KiB
in46.txt AC 48 ms 38608 KiB
in47.txt AC 229 ms 57600 KiB
in48.txt AC 216 ms 56960 KiB
in49.txt AC 282 ms 73896 KiB
in50.txt AC 261 ms 73140 KiB
in51.txt AC 52 ms 39436 KiB
in52.txt AC 163 ms 51228 KiB
in53.txt AC 273 ms 72644 KiB
in54.txt AC 236 ms 57668 KiB
in55.txt AC 229 ms 57872 KiB
in56.txt AC 215 ms 53384 KiB
in57.txt AC 48 ms 38560 KiB
in58.txt AC 48 ms 38600 KiB
in59.txt AC 195 ms 56304 KiB
in60.txt AC 192 ms 54540 KiB
in61.txt AC 198 ms 56236 KiB
in62.txt AC 181 ms 54092 KiB
in63.txt AC 46 ms 38776 KiB
in64.txt AC 47 ms 38472 KiB
in65.txt AC 47 ms 38716 KiB
in66.txt AC 47 ms 38532 KiB
in67.txt AC 46 ms 38472 KiB
in68.txt AC 46 ms 38716 KiB
in69.txt AC 50 ms 38440 KiB
in70.txt AC 51 ms 38960 KiB
in71.txt AC 52 ms 38952 KiB
in72.txt AC 47 ms 38624 KiB
in73.txt AC 47 ms 38664 KiB
in74.txt AC 147 ms 50220 KiB
in75.txt AC 149 ms 50200 KiB
in76.txt AC 46 ms 38688 KiB
in77.txt AC 46 ms 38768 KiB
in78.txt AC 285 ms 73060 KiB
in79.txt AC 196 ms 56352 KiB
in80.txt AC 150 ms 53896 KiB
in81.txt AC 183 ms 55992 KiB
in82.txt AC 216 ms 70888 KiB
sample01.txt AC 46 ms 38664 KiB
sample02.txt AC 46 ms 38604 KiB
sample03.txt AC 47 ms 38496 KiB