Submission #599536

#TimeUsernameProblemLanguageResultExecution timeMemory
599536pedroslreyToll (BOI17_toll)C++17
8 / 100
3086 ms6880 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e4 + 10; vector<pair<int, int>> graph[MAXN]; int dist[MAXN]; bool marc[MAXN]; void dijkstra(int a, int n) { for (int i = 0; i < n; ++i) { dist[i] = 1e9; marc[i] = false; } set<pair<int, int>> s; s.emplace(0, a); dist[a] = 0; while (!s.empty()) { int u = s.begin()->second; s.erase(s.begin()); if (marc[u]) continue; marc[u] = true; for (auto [v, c]: graph[u]) { int d = dist[u] + c; if (dist[v] > d) { dist[v] = d; s.emplace(d, v); } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, q, m, k; cin >> k >> n >> m >> q; for (int i = 0; i < m; ++i) { int u, v, t; cin >> u >> v >> t; graph[u].emplace_back(v, t); } for (int i = 0; i < q; ++i) { int a, b; cin >> a >> b; dijkstra(a, n); if (marc[b]) cout << dist[b] << "\n"; else cout << "-1\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...