mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 18:52:02 +00:00
P2984 [USACO10FEB]Chocolate Giving S
R53548464
This commit is contained in:
parent
b4bcc0d2ee
commit
a4a1d02e43
41
Luogu/problem/P2984/P2984.cpp
Normal file
41
Luogu/problem/P2984/P2984.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int n, m, b, r, s, l, p, q, dist[50005];
|
||||
vector<pair<int, int>> g[50005];
|
||||
bool st[50005];
|
||||
|
||||
void dijkstra() {
|
||||
memset(dist, 0x3f, sizeof(dist));
|
||||
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
|
||||
dist[1] = 0;
|
||||
q.push(make_pair(0, 1));
|
||||
while (!q.empty()) {
|
||||
auto t = q.top();
|
||||
q.pop();
|
||||
if (st[t.second]) continue;
|
||||
for (auto i : g[t.second]) {
|
||||
if (dist[i.first] > t.first + i.second) {
|
||||
dist[i.first] = t.first + i.second;
|
||||
q.push(make_pair(dist[i.first], i.first));
|
||||
}
|
||||
}
|
||||
st[t.second] = true;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n >> m >> b;
|
||||
for (int i = 1; i <= m; i++) {
|
||||
cin >> r >> s >> l;
|
||||
g[r].push_back(make_pair(s, l));
|
||||
g[s].push_back(make_pair(r, l));
|
||||
}
|
||||
dijkstra();
|
||||
for (int i = 1; i <= b; i++) {
|
||||
cin >> p >> q;
|
||||
cout << dist[p] + dist[q] << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user