Submission #1006837

#TimeUsernameProblemLanguageResultExecution timeMemory
1006837overwatch9Toll (BOI17_toll)C++17
8 / 100
3070 ms7260 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 50001; vector <pair <int, int>> adj[maxn]; ll dis[maxn]; int processed[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int K, N, M, O; cin >> K >> N >> M >> O; for (int i = 0; i < M; i++) { int a, b, t; cin >> a >> b >> t; adj[a].push_back({b, t}); } for (int o = 1; o <= O; o++) { int st, ed; cin >> st >> ed; fill(dis, dis + N + 1, 1e18); dis[st] = 0; priority_queue <pair <ll, int>> pq; pq.push({0, st}); while (!pq.empty()) { int s = pq.top().second; pq.pop(); if (processed[s] == o) continue; processed[s] = o; for (auto i : adj[s]) { if (dis[i.first] > dis[s] + i.second) { dis[i.first] = dis[s] + i.second; pq.push({-dis[i.first], i.first}); } } } if (dis[ed] == 1e18) dis[ed] = -1; cout << dis[ed] << '\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...