Submission #981752

#TimeUsernameProblemLanguageResultExecution timeMemory
981752kaopjEvacuation plan (IZhO18_plan)C++14
0 / 100
170 ms19068 KiB
#include <bits/stdc++.h> using namespace std; #define int long long vector<pair<int,int>> edge[100001]; int n,m; int dist[100001]; bool vis[100001]; int dfs(int x,int t) { vis[x]=1; if (t == x||!dist[x]) { return dist[x]; } int maxi=0; for (auto i:edge[x]) { if (vis[i.second]) { continue; } maxi = max(maxi,dfs(i.second,t)); } return min(dist[x],maxi); } signed main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; 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; for (int i=0;i<=n;i++) { dist[i] = 1e9; } 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--) { memset(vis,0,sizeof vis); 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...