結果

問題 No.1473 おでぶなおばけさん
ユーザー neko_the_shadowneko_the_shadow
提出日時 2021-04-14 00:51:14
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 6,386 bytes
コンパイル時間 3,155 ms
コンパイル使用メモリ 102,756 KB
実行使用メモリ 120,192 KB
最終ジャッジ日時 2023-09-12 15:20:28
合計ジャッジ時間 57,295 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
51,568 KB
testcase_01 AC 67 ms
51,288 KB
testcase_02 AC 1,555 ms
102,948 KB
testcase_03 AC 1,059 ms
89,600 KB
testcase_04 AC 1,202 ms
83,316 KB
testcase_05 AC 716 ms
68,028 KB
testcase_06 AC 1,607 ms
94,244 KB
testcase_07 AC 1,404 ms
100,040 KB
testcase_08 TLE -
testcase_09 AC 1,358 ms
99,464 KB
testcase_10 AC 756 ms
67,680 KB
testcase_11 AC 801 ms
67,096 KB
testcase_12 AC 699 ms
67,496 KB
testcase_13 AC 538 ms
64,872 KB
testcase_14 AC 485 ms
64,488 KB
testcase_15 AC 666 ms
67,468 KB
testcase_16 AC 641 ms
67,604 KB
testcase_17 AC 228 ms
59,120 KB
testcase_18 AC 316 ms
59,320 KB
testcase_19 AC 837 ms
69,392 KB
testcase_20 AC 1,016 ms
79,924 KB
testcase_21 AC 1,140 ms
80,972 KB
testcase_22 AC 1,033 ms
93,440 KB
testcase_23 AC 962 ms
89,340 KB
testcase_24 AC 933 ms
82,224 KB
testcase_25 TLE -
testcase_26 TLE -
testcase_27 AC 852 ms
69,436 KB
testcase_28 TLE -
testcase_29 AC 1,243 ms
88,480 KB
testcase_30 AC 1,646 ms
93,732 KB
testcase_31 AC 1,517 ms
105,388 KB
testcase_32 AC 1,306 ms
93,772 KB
testcase_33 AC 1,091 ms
82,748 KB
testcase_34 AC 866 ms
77,332 KB
testcase_35 AC 720 ms
69,288 KB
testcase_36 AC 1,244 ms
80,568 KB
testcase_37 AC 1,663 ms
100,216 KB
testcase_38 AC 439 ms
65,912 KB
testcase_39 AC 690 ms
65,884 KB
testcase_40 AC 675 ms
67,116 KB
testcase_41 AC 599 ms
64,176 KB
testcase_42 AC 594 ms
66,432 KB
testcase_43 AC 1,009 ms
90,052 KB
testcase_44 AC 1,096 ms
102,124 KB
testcase_45 AC 1,016 ms
93,540 KB
testcase_46 AC 1,131 ms
89,280 KB
testcase_47 AC 1,078 ms
93,344 KB
testcase_48 AC 1,131 ms
95,824 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.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
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<int[]>> nexts = new HashMap<>();
        for (int i = 0; i < m; i++) {
            int s = stdin.nextInt();
            int t = stdin.nextInt();
            int d = stdin.nextInt();
            nexts.computeIfAbsent(s, unused -> new ArrayList<>()).add(new int[] {t, d});
            nexts.computeIfAbsent(t, unused -> new ArrayList<>()).add(new int[] {s, d});
        }
        
        int ok = 0;
        int ng = 1000000000+1;
        while (Math.abs(ok-ng)>1) {
            int mi = (ok+ng)/2;

            
            Deque<Integer> stack = new ArrayDeque<>();
            Set<Integer> visited = new HashSet<>();
            stack.add(1);
            visited.add(1);
            while (!stack.isEmpty()) {
                int cur = stack.pop();
                for (int[] next : nexts.get(cur)) {
                    int nxt = next[0];
                    int d = next[1];
                    if (visited.contains(nxt)) continue;
                    if (mi <= d) {
                        stack.add(nxt);
                        visited.add(nxt);
                    }
                }
            }
            if (visited.contains(n)) {
                ok = mi;
            } else {
                ng = mi;
            }
        }
        
        
        Map<Integer, Integer> score = new HashMap<>();
        Deque<Integer> stack = new ArrayDeque<>();
        score.put(1, 0);
        stack.add(1);
        while (!stack.isEmpty()) {
            int cur = stack.pop();
            for (int[] next : nexts.get(cur)) {
                int nxt = next[0];
                int d = next[1];
                if (ok <= d && score.get(cur) + 1 < score.getOrDefault(nxt, Integer.MAX_VALUE)) {
                    score.put(nxt, score.get(cur)+1);
                    stack.add(nxt);
                }
            }
        }
        
        stdout.println(ok, score.get(n));
    }
    

    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