# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
864522 | maks007 | Toll (BOI17_toll) | C++14 | 74 ms | 3584 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Bismi ALlah
#include "bits/stdc++.h"
using namespace std;
signed main () {
int n, m, k, query;
cin >> k >> n >> m >> query;
vector<pair <int,int>> g[n];
for(int i = 0; i < m; i ++) {
int u, v;
cin >> u >> v;
int w;
cin >> w;
g[u].push_back({v, w});
}
int dp[n], parent[n];
for(int i = 0; i < n; i ++) dp[i] = 1e9, parent[i] = 0;
for(int i = 0; i < k; i ++) dp[i] = 0;
for(int i = 0; i < n; i ++) {
if(dp[i] == 1e9) continue;
for(auto [u, w] : g[i]) {
if(dp[u] > dp[i] + w) {
dp[u] = dp[i] + w;
parent[u] = dp[i];
}
}
}
while(query --) {
int a, b;
cin >> a >> b;
if(dp[b] == 1e9) cout << -1 << "\n";
else
cout << dp[b] - dp[a] << "\n";
}
return 0;
}
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... |