제출 #495109

#제출 시각아이디문제언어결과실행 시간메모리
495109NalrimetEvacuation plan (IZhO18_plan)C++17
0 / 100
251 ms10560 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int inf = 1000000000; #define F first #define S second #define pb push_back vector<pair<int, int>> g[N]; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q; int n, m, d[N], p[N], k, qq; int main() { cin >> n >> m; for(int i = 1, a, b, w; i <= m; ++i){ cin >> a >> b >> w; g[a].pb({b, w}); g[b].pb({a, w}); } for(int i = 1; i <= n; ++i){ d[i] = inf; } cin >> k; for(int i = 1, x; i <= k; ++i){ cin >> x; d[x] = 0; q.push({0, x}); } while(!q.empty()){ int v = q.top().S; int d_v = q.top().F; q.pop(); if(d_v != d[v]) continue; for(auto edge : g[v]){ int to = edge.F; int len = edge.S; if(d[v] + len < d[to]){ d[to] = d[v] + len; p[to] = v; q.push({d[to], to}); } } } cin >> qq; while(qq--){ int s, t; cin >> s >> t; cout << max(d[s], d[t]) << '\n'; } 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...