This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
vector<pair<int, int>> g[100002];
priority_queue<pair<int, int>> q;
int d[100002], p[100002];
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
d[i] = 1'000'000'00 +69;
for (int i = 0; i < m; i++)
{
int a, b, w;
cin >> a >> b >> w;
g[a].push_back({ b,w });
g[b].push_back({ a,w });
}
int k;
cin >> k;
for (int i = 0; i < k; i++)
{
int x;
cin >> x;
d[x] = 0;
q.push({ 0, x });
}
while (!q.empty()) {
int sz = -q.top().first;
int v = q.top().second;
q.pop();
if (sz > d[v])continue;
for (auto to : g[v])
if (to.second + d[v] < d[to.first])
{
d[to.first] = to.second + d[v];
q.push({ -d[to.first], to.first });
}
}
int Q;
cin >> Q;
while (Q--)
{
int s, t;
cin >> s >> t;
for (int i = 1; i <= n; i++)
p[i] = -1'000'000;
p[s] = d[s];
q.push({ d[s], s });
while (!q.empty()) {
int sz = q.top().first;
int v = q.top().second;
q.pop();
if (sz < p[v])continue;
for (auto to : g[v])
if (min(d[to.first], p[v]) > p[to.first])
{
p[to.first] = min(d[to.first], p[v]);
q.push({ p[to.first], to.first });
}
}
cout << p[t] << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |