제출 #349812

#제출 시각아이디문제언어결과실행 시간메모리
349812VictorToll (BOI17_toll)C++17
8 / 100
3084 ms14828 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 = a - 1; i >= (b); --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 endl '\n' #define umap unordered_map #define uset unordered_set #define INF 1000000000 typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(NULL); set<pair<ll, int>> s, pq; vector<ll> dist; vector<pair<int, ll>> graph[50001]; int k, n, m, o; cin >> k >> n >> m >> o; rep(i, 0, m) { ll a, b, t; cin >> a >> b >> t; graph[a].emplace_back(b, t); } rep(i, 0, n) s.emplace(1e15, i); while (o--) { dist.assign(n, 1e15); pq = s; ll a, b; cin >> a >> b; pq.erase({1e15, a}); pq.emplace(0, a); while (!pq.empty()) { ll cost, u; tie(cost, u) = *pq.begin(); pq.erase(pq.begin()); trav(edge, graph[u]) { ll w = edge.second; int v = edge.first; if (cost + w >= dist[v]) continue; pq.erase({dist[v], v}); pq.insert({cost + w, v}); dist[v] = cost + w; } } if (dist[b] == 1e15) cout<<-1<<endl; 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...