結果

問題 No.1473 おでぶなおばけさん
ユーザー 👑 hos.lyrichos.lyric
提出日時 2021-04-09 21:49:45
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 751 ms / 2,000 ms
コード長 2,371 bytes
コンパイル時間 1,280 ms
コンパイル使用メモリ 110,760 KB
実行使用メモリ 22,588 KB
最終ジャッジ日時 2023-09-04 12:32:04
合計ジャッジ時間 14,987 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 484 ms
18,572 KB
testcase_03 AC 227 ms
21,868 KB
testcase_04 AC 280 ms
14,612 KB
testcase_05 AC 90 ms
4,420 KB
testcase_06 AC 432 ms
18,600 KB
testcase_07 AC 410 ms
19,600 KB
testcase_08 AC 658 ms
18,860 KB
testcase_09 AC 347 ms
19,840 KB
testcase_10 AC 124 ms
7,460 KB
testcase_11 AC 133 ms
13,860 KB
testcase_12 AC 125 ms
13,352 KB
testcase_13 AC 79 ms
10,964 KB
testcase_14 AC 56 ms
4,952 KB
testcase_15 AC 112 ms
10,232 KB
testcase_16 AC 108 ms
12,516 KB
testcase_17 AC 10 ms
4,376 KB
testcase_18 AC 16 ms
4,380 KB
testcase_19 AC 125 ms
11,804 KB
testcase_20 AC 167 ms
15,160 KB
testcase_21 AC 203 ms
13,684 KB
testcase_22 AC 142 ms
11,800 KB
testcase_23 AC 124 ms
12,308 KB
testcase_24 AC 118 ms
11,872 KB
testcase_25 AC 611 ms
14,980 KB
testcase_26 AC 595 ms
14,192 KB
testcase_27 AC 124 ms
13,352 KB
testcase_28 AC 751 ms
16,608 KB
testcase_29 AC 360 ms
13,964 KB
testcase_30 AC 423 ms
14,228 KB
testcase_31 AC 242 ms
18,252 KB
testcase_32 AC 266 ms
17,532 KB
testcase_33 AC 155 ms
12,532 KB
testcase_34 AC 93 ms
15,148 KB
testcase_35 AC 85 ms
11,868 KB
testcase_36 AC 285 ms
13,988 KB
testcase_37 AC 553 ms
14,144 KB
testcase_38 AC 56 ms
4,380 KB
testcase_39 AC 113 ms
13,688 KB
testcase_40 AC 107 ms
7,452 KB
testcase_41 AC 96 ms
6,652 KB
testcase_42 AC 96 ms
7,448 KB
testcase_43 AC 154 ms
22,284 KB
testcase_44 AC 155 ms
22,588 KB
testcase_45 AC 156 ms
21,640 KB
testcase_46 AC 197 ms
15,404 KB
testcase_47 AC 244 ms
17,216 KB
testcase_48 AC 237 ms
18,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum INF = 10^^9 + 10;

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const M = readInt();
      auto A = new int[M];
      auto B = new int[M];
      auto D = new int[M];
      foreach (i; 0 .. M) {
        A[i] = readInt() - 1;
        B[i] = readInt() - 1;
        D[i] = readInt();
      }
      
      auto G = new int[][N];
      foreach (i; 0 .. M) {
        G[A[i]] ~= i;
        G[B[i]] ~= i;
      }
      
      int calc(int w) {
        DList!int que;
        auto dist = new int[N];
        dist[] = N + 1;
        dist[0] = 0;
        que ~= 0;
        for (; !que.empty; ) {
          const u = que.front;
          que.removeFront;
          foreach (i; G[u]) {
            if (D[i] >= w) {
              const v = A[i] ^ B[i] ^ u;
              if (chmin(dist[v], dist[u] + 1)) {
                que ~= v;
              }
            }
          }
        }
        return dist[N - 1];
      }
      
      int lo = 0, hi = D.maxElement + 1;
      for (; lo + 1 < hi; ) {
        const mid = (lo + hi) / 2;
        ((calc(mid) < N) ? lo : hi) = mid;
      }
      const res = calc(lo);
      writeln(lo, " ", res);
    }
  } catch (EOFException e) {
  }
}
0