結果

問題 No.1473 おでぶなおばけさん
ユーザー neko_the_shadowneko_the_shadow
提出日時 2021-04-14 00:59:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,749 ms / 2,000 ms
コード長 5,983 bytes
コンパイル時間 2,864 ms
コンパイル使用メモリ 93,360 KB
実行使用メモリ 77,764 KB
最終ジャッジ日時 2024-06-30 03:20:42
合計ジャッジ時間 44,523 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
37,964 KB
testcase_01 AC 71 ms
37,944 KB
testcase_02 AC 1,194 ms
74,920 KB
testcase_03 AC 925 ms
67,052 KB
testcase_04 AC 982 ms
62,652 KB
testcase_05 AC 558 ms
51,724 KB
testcase_06 AC 1,210 ms
67,304 KB
testcase_07 AC 1,197 ms
77,764 KB
testcase_08 AC 1,655 ms
77,440 KB
testcase_09 AC 1,129 ms
77,352 KB
testcase_10 AC 603 ms
55,484 KB
testcase_11 AC 643 ms
55,748 KB
testcase_12 AC 595 ms
55,040 KB
testcase_13 AC 479 ms
52,472 KB
testcase_14 AC 404 ms
51,224 KB
testcase_15 AC 595 ms
55,040 KB
testcase_16 AC 592 ms
53,384 KB
testcase_17 AC 204 ms
46,844 KB
testcase_18 AC 258 ms
47,664 KB
testcase_19 AC 705 ms
54,784 KB
testcase_20 AC 944 ms
64,516 KB
testcase_21 AC 940 ms
60,420 KB
testcase_22 AC 741 ms
65,436 KB
testcase_23 AC 666 ms
65,832 KB
testcase_24 AC 689 ms
64,368 KB
testcase_25 AC 1,749 ms
66,472 KB
testcase_26 AC 1,597 ms
67,120 KB
testcase_27 AC 665 ms
52,200 KB
testcase_28 AC 1,381 ms
76,172 KB
testcase_29 AC 1,031 ms
61,996 KB
testcase_30 AC 1,173 ms
63,488 KB
testcase_31 AC 1,147 ms
75,472 KB
testcase_32 AC 995 ms
67,576 KB
testcase_33 AC 881 ms
64,316 KB
testcase_34 AC 730 ms
54,980 KB
testcase_35 AC 630 ms
53,480 KB
testcase_36 AC 920 ms
56,816 KB
testcase_37 AC 1,210 ms
64,084 KB
testcase_38 AC 367 ms
49,884 KB
testcase_39 AC 610 ms
55,104 KB
testcase_40 AC 598 ms
54,760 KB
testcase_41 AC 628 ms
54,648 KB
testcase_42 AC 638 ms
54,600 KB
testcase_43 AC 721 ms
67,376 KB
testcase_44 AC 719 ms
66,472 KB
testcase_45 AC 716 ms
66,464 KB
testcase_46 AC 840 ms
64,364 KB
testcase_47 AC 921 ms
66,932 KB
testcase_48 AC 898 ms
64,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package _1473;
import java.io.BufferedReader;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.regex.Pattern;

public class Main {
    public void exec() {
        int n = stdin.nextInt();
        int m = stdin.nextInt();
        Map<Integer, List<Edge>> edges = new HashMap<>();
        for (int i = 0; i < m; i++) {
            int s = stdin.nextInt()-1;
            int t = stdin.nextInt()-1;
            int d = stdin.nextInt();
            edges.computeIfAbsent(s, unused -> new ArrayList<>()).add(new Edge(t, d));
            edges.computeIfAbsent(t, unused -> new ArrayList<>()).add(new Edge(s, d));
        }
        
        int ok = 0;
        int ng = 1000000000+1;
        int ans = 0;
        while (Math.abs(ok-ng)>1) {
            int mi = (ok+ng)/2;

            
            Deque<Integer> stack = new ArrayDeque<>();
            int[] count = new int[n];
            stack.add(0);
            Arrays.fill(count, Integer.MAX_VALUE);
            count[0]=0;

            while (!stack.isEmpty()) {
                int cur = stack.pop();
                for (Edge e : edges.get(cur)) {
                    if (mi <= e.d && count[cur]+1 < count[e.next]) {
                        stack.add(e.next);
                        count[e.next] = count[cur]+1;
                    }
                }
            }
            if (count[n-1]!=Integer.MAX_VALUE) {
                ok = mi;
                ans = count[n-1];
            } else {
                ng = mi;
            }
        }
        
        stdout.println(ok, ans);
    }
    
    public class Edge {
        public int next;
        public int d;
        public Edge(int next, int d) {
            super();
            this.next = next;
            this.d = d;
        }
    }
    

    private static final Stdin stdin = new Stdin(System.in);
    private static final Stdout stdout = new Stdout(System.out);

    public static void main(String[] args) {
        try {
            new Main().exec();
        } finally {
            stdout.flush();
        }
    }

    public static class Stdin {
        private Deque<String> queue;
        private BufferedReader in;
        private Pattern space;

        public Stdin(InputStream in) {
            this.queue = new ArrayDeque<>();
            this.in = new BufferedReader(new InputStreamReader(in));
            this.space = Pattern.compile(" ");
        }

        public String nextString() {
            if (queue.isEmpty()) {
                try {
                    String line = in.readLine();
                    if (line == null) {
                        throw new EOFException();
                    }
                    space.splitAsStream(line).forEach(this.queue::addLast);
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return queue.removeFirst();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

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

        public long nextLong() {
            return Long.parseLong(nextString());
        }
        
        public BigInteger nextBigInteger() {
            return new BigInteger(nextString());
        }

        public String[] nextStringArray(int n) {
            String[] a = new String[n];
            for (int i = 0; i < n; i++) a[i] = nextString();
            return a;
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) {
            double[] a = new double[n];
            for (int i = 0; i < n; i++) a[i] = nextDouble();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
        
        public BigInteger[] nexBigIntegerArray(int n) {
            BigInteger[] a = new BigInteger[n];
            for (int i = 0; i < n; i++) a[i] = nextBigInteger();
            return a;
        }
        
        public List<Integer> nextIntegerList(int n) {
            return nextList(n, this::nextInt);
        }
        
        public List<Long> nextLongList(int n) {
            return nextList(n, this::nextLong);
        }
        
        public List<Double> nextDoubleList(int n) {
            return nextList(n, this::nextDouble);
        }
        
        public List<String> nextStringList(int n) {
            return nextList(n, this::nextString);
        }
        
        public List<BigInteger> nextBigIntegerList(int n) {
            return nextList(n, this::nextBigInteger);
        }
        
        private <T> List<T> nextList(int n, Supplier<T> supplier) {
            List<T> a = new ArrayList<>();
            for (int i = 0; i < n; i++) a.add(supplier.get());
            return a;
        }
    }

    public static class Stdout {
        private PrintWriter stdout;

        public Stdout(PrintStream stdout) {
            this.stdout =  new PrintWriter(stdout, false);
        }

        public void println(Object ... objs) {
            for (int i = 0, len = objs.length; i < len; i++) {
                stdout.print(objs[i]);
                if (i != len-1) stdout.print(' ');
            }
            stdout.println();
        }

        public void flush() {
            stdout.flush();
        }
    }
}
0