제출 #391044

#제출 시각아이디문제언어결과실행 시간메모리
391044VictorToll (BOI17_toll)C++17
8 / 100
3080 ms9060 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); } set<ii> pq; rep(i, 0, o) { fill(dist, dist + n, INF); int a, b; cin >> a >> b; 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); } } 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...