이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define int long long
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
using namespace std;
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int TN = 1;
int n, m;
int k, Q;
int d[N];
vector<pair<int, int>> verr[N];
void solve() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y, len;
cin >> x >> y >> len;
verr[x].push_back({y, len});
verr[y].push_back({x, len});
}
cin >> k;
for (int i = 1; i <= k; i++) {
int x;
cin >> x;
verr[0].pb({x, 0});
}
for (int i = 0; i < N; i++) {
d[i] = INF;
}
d[0] = 0;
set<pair<int, int>> q;
q.insert({d[0], 0});
while (!q.empty()) {
int x = q.begin()->se;
q.erase(q.begin());
for (auto i: verr[x]) {
int to = i.fi, len = i.se;
if (d[x] + len < d[to]) {
q.erase({d[to], to});
d[to] = d[x] + len;
q.insert({d[to], to});
}
}
}
cin >> Q;
while (Q--) {
int x, y;
cin >> x >> y;
cout << min(d[x], d[y]) << "\n";
}
return;
}
signed main() {
// ios_base::sync_with_stdio(0);
// in; out; // cin >> TN;
while (TN--) solve();
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... |