Submission #20300124


Source Code Expand

Copy
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 = 10L^^18;

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const M = readInt();
      const X = readInt() - 1;
      const Y = readInt() - 1;
      auto A = new int[M];
      auto B = new int[M];
      auto T = new long[M];
      auto K = new long[M];
      foreach (i; 0 .. M) {
        A[i] = readInt() - 1;
        B[i] = readInt() - 1;
        T[i] = readLong();
        K[i] = readLong();
      }
      
      auto G = new int[][N];
      foreach (i; 0 .. M) {
        G[A[i]] ~= i;
        G[B[i]] ~= i;
      }
      
      alias Entry = Tuple!(long, "c", int, "u");
      BinaryHeap!(Array!Entry, "a.c > b.c") que;
      auto dist = new long[N];
      dist[] = INF;
      dist[X] = 0;
      que.insert(Entry(0, X));
      for (; !que.empty; ) {
        const c = que.front.c;
        const u = que.front.u;
        que.removeFront;
        if (dist[u] == c) {
          foreach (i; G[u]) {
            const cc = (c + K[i] - 1) / K[i] * K[i] + T[i];
            const v = A[i] ^ B[i] ^ u;
            if (chmin(dist[v], cc)) {
              que.insert(Entry(cc, v));
            }
          }
        }
      }
      debug {
        writeln("dist = ", dist);
      }
      writeln((dist[Y] >= INF) ? -1 : dist[Y]);
    }
  } catch (EOFException e) {
  }
}

Submission Info

Submission Time
Task E - Train
User hos_lyric
Language D (LDC 1.20.1)
Score 500
Code Size 2543 Byte
Status AC
Exec Time 112 ms
Memory 12736 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 28
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All hand.txt, max_01.txt, random_01.txt, random_02.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Case Name Status Exec Time Memory
hand.txt AC 10 ms 3284 KB
max_01.txt AC 107 ms 9388 KB
random_01.txt AC 90 ms 9700 KB
random_02.txt AC 61 ms 8128 KB
random_05.txt AC 64 ms 5596 KB
random_06.txt AC 62 ms 5716 KB
random_07.txt AC 81 ms 7360 KB
random_08.txt AC 74 ms 12736 KB
random_11.txt AC 64 ms 5500 KB
random_12.txt AC 55 ms 5092 KB
random_13.txt AC 53 ms 5448 KB
random_14.txt AC 68 ms 5908 KB
random_15.txt AC 76 ms 6824 KB
random_16.txt AC 65 ms 5740 KB
random_17.txt AC 78 ms 7296 KB
random_18.txt AC 57 ms 5460 KB
random_21.txt AC 103 ms 9512 KB
random_22.txt AC 105 ms 9372 KB
random_23.txt AC 102 ms 9564 KB
random_24.txt AC 99 ms 9304 KB
random_31.txt AC 112 ms 8916 KB
random_32.txt AC 111 ms 8504 KB
random_33.txt AC 109 ms 8616 KB
random_34.txt AC 107 ms 8892 KB
sample_01.txt AC 3 ms 3228 KB
sample_02.txt AC 4 ms 3228 KB
sample_03.txt AC 4 ms 3368 KB
sample_04.txt AC 7 ms 3380 KB