Submission #391045

#TimeUsernameProblemLanguageResultExecution timeMemory
391045VictorToll (BOI17_toll)C++17
18 / 100
3086 ms8712 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define per(i, a, b) for (int i = b - 1; i >= (a); --i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) x.size() #define pb push_back #define umap unordered_map #define uset unordered_set typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef long long ll; const int INF = 1000000007; vii graph[50001]; int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int k, n, m, o, dist[50001]; cin >> k >> n >> m >> o; rep(i, 0, m) { int u, v, w; cin >> u >> v >> w; graph[u].emplace_back(v, w); } int preva = -1; set<ii> pq; rep(i, 0, o) { int a, b; cin >> a >> b; if (preva != a) { fill(dist, dist + n, INF); dist[a] = 0; rep(i, 0, n) pq.insert({dist[i], i}); while (!pq.empty()) { int d, u; tie(d, u) = *pq.begin(); pq.erase(pq.begin()); trav(edge, graph[u]) { int v, w; tie(v, w) = edge; if (d + w >= dist[v]) continue; pq.erase({dist[v], v}); dist[v] = d + w; pq.emplace(d + w, v); } } } preva=a; if (dist[b] == INF) cout << "-1\n"; else cout << dist[b] << endl; } return 0; }
#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...