이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/** @BY_KUTBILIM **/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).end()
const int inf = (int)1e9+7;
vector<vector<pair<int,int>>> g;
int main(){
ios_base::sync_with_stdio(false);
cin.tie();
int n, m;
cin >> n >> m;
g.resize(n);
vector<vector<int>> road(n, vector<int> (n, 0));
for(int i = 0; i < m; i++){
int u, v, w;
cin >> v >> u >> w;
v--;
u--;
g[v].pb({u, w});
g[u].pb({v, w});
road[v][u] = road[u][v] = 1;
}
int k;
cin >> k;
int r[k];
priority_queue<pair<int,int>> q;
vector<int> d(n, inf), used(n, 0);
for(int i = 0; i < k; i++){
cin >> r[i];
r[i]--;
q.push({0, r[i]});
d[r[i]] = 0;
}
while(!q.empty()){
int a = q.top().second; q.pop();
if(used[a]) continue;
for(auto u : g[a]){
int b = u.first, w = u.second;
if(d[a] + w < d[b]){
d[b] = d[a] + w;
q.push({-d[b], b});
}
}
}
int Q;
cin >> Q;
while(Q--){
int s, t;
cin >> s >> t;
s--;
t--;
if(road[s][t]){
cout << min(d[s], d[t]) << endl;
} else{
}
}
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... |