이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |