Archived
00:04(120)
This commit is contained in:
1 parent
c9a42541c4
commit
64eda003fc
1 file changed
+50
@@ -0,0 +1,50 @@
|
|||||||
|
#include<bits/stdc++.h>
|
||||||
|
using namespace std;
|
||||||
|
int c, n, m, d, q; // 25 500 5e5 20 1e5
|
||||||
|
int w[500005];
|
||||||
|
vector<pair<int, int>> fri[500505];
|
||||||
|
int de[500505];
|
||||||
|
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
|
||||||
|
void dig(int s) {
|
||||||
|
memset(de, 0x7f, sizeof(de[0]) * (n + m + 1));
|
||||||
|
de[s] = 0;
|
||||||
|
pq.push({0, s});
|
||||||
|
while(!pq.empty()) {
|
||||||
|
pair<int, int> u = pq.top();
|
||||||
|
pq.pop();
|
||||||
|
for(pair<int, int> v : fri[u.second]) {
|
||||||
|
if(de[v.second] > de[u.second] + v.first) {
|
||||||
|
de[v.second] = de[u.second] + v.first;
|
||||||
|
pq.push({de[v.second], v.second});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int main() {
|
||||||
|
freopen("subway.in", "r", stdin);
|
||||||
|
freopen("subway.out", "w", stdout);
|
||||||
|
scanf("%d%d%d%d%d", &c, &n, &m, &d, &q);
|
||||||
|
for(int i = 1; i <= m; ++i) {
|
||||||
|
scanf("%d", &w[i]);
|
||||||
|
}
|
||||||
|
for(int i = 1, k; i <= n; ++i) {
|
||||||
|
scanf("%d", &k);
|
||||||
|
for(int j = 1, sta, ti; j <= k; ++j) {
|
||||||
|
scanf("%d%d", &sta, &ti);
|
||||||
|
fri[m + i].push_back({ti, sta});
|
||||||
|
fri[sta].push_back({ti, m + i});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(q--) {
|
||||||
|
int x, y;
|
||||||
|
scanf("%d%d", &x, &y);
|
||||||
|
dig(x);
|
||||||
|
printf("%d\n", w[x] + w[y] + de[y]);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
g++ subway/subway.cpp -o subway/subway -std=c++14 -O2 -static -Wall && cp subway/subway ~ && chmod +x ~/subway && ~/subway
|
||||||
|
|
||||||
|
500 条线路各视为图上的一个点,分别和地铁站连线
|
||||||
|
*/
|
||||||
Reference in new issue
Block a user