Submission #50587352


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  int n, m;
  cin >> n >> m;
  vector<int> l(m), d(m), k(m), c(m), a(m), b(m);
  vector<vector<int>> g(n);
  for (int i = 0; i < m; ++i) {
    cin >> l[i] >> d[i] >> k[i] >> c[i] >> a[i] >> b[i];
    --a[i], --b[i];
    g[b[i]].push_back(i);
  }
  vector<long long> dist(n, -1);
  dist[n - 1] = 2e18;
  priority_queue<pair<long long, int>> q;
  q.emplace(dist[n - 1], n - 1);
  vector<char> used(n);
  while (!q.empty()) {
    auto [_, v] = q.top();
    q.pop();
    if (used[v]) continue;
    used[v] = true;
    for (int i : g[v]) {
      if (dist[v] < l[i] + c[i]) continue;
      int x = min<long long>(k[i] - 1, (dist[v] - l[i] - c[i]) / d[i]);
      long long y = l[i] + 1ll * x * d[i];
      if (dist[a[i]] < y) {
        dist[a[i]] = y;
        q.emplace(y, a[i]);
      }
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    if (dist[i] == -1) cout << "Unreachable";
    else cout << dist[i];
    cout << '\n';
  }

  return 0;
}

Submission Info

Submission Time
Task E - Last Train
User achvanov
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1097 Byte
Status AC
Exec Time 136 ms
Memory 19936 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 33
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3624 KiB
00_sample_01.txt AC 1 ms 3368 KiB
00_sample_02.txt AC 1 ms 3508 KiB
01_random_03.txt AC 130 ms 19884 KiB
01_random_04.txt AC 131 ms 19920 KiB
01_random_05.txt AC 127 ms 19936 KiB
01_random_06.txt AC 136 ms 19840 KiB
01_random_07.txt AC 128 ms 19884 KiB
01_random_08.txt AC 112 ms 19132 KiB
01_random_09.txt AC 115 ms 19160 KiB
01_random_10.txt AC 98 ms 18184 KiB
01_random_11.txt AC 71 ms 9804 KiB
01_random_12.txt AC 111 ms 15856 KiB
01_random_13.txt AC 53 ms 9312 KiB
01_random_14.txt AC 22 ms 7028 KiB
01_random_15.txt AC 22 ms 5736 KiB
01_random_16.txt AC 38 ms 11596 KiB
01_random_17.txt AC 87 ms 18280 KiB
01_random_18.txt AC 87 ms 18280 KiB
01_random_19.txt AC 86 ms 18228 KiB
01_random_20.txt AC 90 ms 18168 KiB
01_random_21.txt AC 87 ms 18096 KiB
01_random_22.txt AC 76 ms 11860 KiB
01_random_23.txt AC 55 ms 12732 KiB
01_random_24.txt AC 46 ms 12780 KiB
01_random_25.txt AC 118 ms 19808 KiB
01_random_26.txt AC 114 ms 19828 KiB
01_random_27.txt AC 117 ms 19840 KiB
01_random_28.txt AC 116 ms 19872 KiB
01_random_29.txt AC 9 ms 9624 KiB
01_random_30.txt AC 8 ms 4180 KiB
01_random_31.txt AC 30 ms 6348 KiB
01_random_32.txt AC 55 ms 8844 KiB