Submission #793501

#TimeUsernameProblemLanguageResultExecution timeMemory
793501asdfgraceToll (BOI17_toll)C++17
100 / 100
2213 ms4480 KiB
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1000000007; //998244353;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int k, n, m, q;
  cin >> k >> n >> m >> q;
  vector<vector<pair<int, int>>> edges(n);
  for (int i = 0; i < m; ++i) {
    int a, b, w;
    cin >> a >> b >> w;
    edges[a].push_back({b, w});
  }
  vector<int> best(n, INF);
  while (q--) {
    int a, b;
    cin >> a >> b;
    fill(best.begin() + a, best.begin() + b + 1, INF);
    best[a] = 0;
    for (int i = a; i < b; ++i) {
      for (auto [next, wt] : edges[i]) {
        best[next] = min(best[next], best[i] + wt);
      }
    }
    if (best[b] == INF) cout << -1 << '\n';
    else cout << best[b] << '\n';
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...