제출 #981706

#제출 시각아이디문제언어결과실행 시간메모리
981706kaopjEvacuation plan (IZhO18_plan)C++17
0 / 100
425 ms524288 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<int,int>> edge[100001]; int n,m; int dist[100001]; int dfs(int x,int t) { int ans=dist[x]; if (t == x) { return ans; } int maxi=0; for (auto i:edge[x]) { maxi = max(maxi,dfs(i.second,t)); } return min(ans,maxi); } int main() { cin >> n >> m; memset(dist,1e9,sizeof dist); int x,y,d; for (int i =0;i<m;i++) { cin >> x >> y >> d; edge[x].push_back({d,y}); edge[y].push_back({d,x}); } int q; cin >> q; priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq; while (q--) { cin >> x; pq.push({0,x}); dist[x]=0; } while (!pq.empty()) { auto u = pq.top(); pq.pop(); if (dist[u.second] < u.first) { continue; } for (auto i:edge[u.second]) { if (dist[i.second] > i.first+u.first) { dist[i.second] = i.first+u.first; pq.push({dist[i.second],i.second}); } } } cin >> q; while (q--) { cin >> x >> y; cout << dfs(x,y) << '\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...