Submission #338448

#TimeUsernameProblemLanguageResultExecution timeMemory
338448boykutEvacuation plan (IZhO18_plan)C++14
23 / 100
435 ms28520 KiB
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector <pair<int,int>> g[1+n]; for (int i = 0; i < m; i++) { int u, v, cost; cin >> u >> v >> cost; g[u].push_back({v, cost}); g[v].push_back({u, cost}); } int k; cin >> k; vector <int> r(k); for (int i = 0; i < k; i++) { cin >> r[i]; } priority_queue <pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> qw; vector <int> used(1 + n,0); vector <int> d(1 + n,INT_MAX); for (int i = 0; i < k; i++) { qw.push({0, r[i]}); d[r[i]] = 0; } while (!qw.empty()) { int v = qw.top().second; qw.pop(); if (used[v]) continue; used[v] = 1; for (pair<int,int> i : g[v]) { int to = i.first, len = i.second; if (d[v] + len < d[to]) { d[to] = d[v] + len; qw.push({d[to], to}); } } } int q; cin >> q; for (int tmp = q; tmp--;) { int s, t; cin >> s >> t; cout << min(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...