# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1264423 | mingga | Toll (BOI17_toll) | C++20 | 1624 ms | 4616 KiB |
// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 50005;
int k, n, m, q;
ll f[N];
vector<pair<int, int>> g[N];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> k >> n >> m >> q;
for(int i = 1; i <= m; i++) {
int a, b, t; cin >> a >> b >> t;
g[b].pb({a, t});
}
for(int i = 1; i <= q; i++) {
int a, b; cin >> a >> b;
for(int j = 1; j <= n; j++) f[j] = 2e18;
f[a] = 0;
for(int j = a + 1; j <= b; j++) {
for(auto [v, w] : g[j]) {
f[j] = min(f[j], f[v] + w);
}
}
if(f[b] == 2e18) f[b] = -1;
cout << f[b] << ln;
}
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |