Archived
00:15(160)
This commit is contained in:
1 parent
64eda003fc
commit
d09b9c8dc2
1 file changed
+19
-2
+19
-2
@@ -4,6 +4,7 @@ int c, n, m, d, q; // 25 500 5e5 20 1e5
|
|||||||
int w[500005];
|
int w[500005];
|
||||||
vector<pair<int, int>> fri[500505];
|
vector<pair<int, int>> fri[500505];
|
||||||
int de[500505];
|
int de[500505];
|
||||||
|
int dline[505][505];
|
||||||
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
|
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
|
||||||
void dig(int s) {
|
void dig(int s) {
|
||||||
memset(de, 0x7f, sizeof(de[0]) * (n + m + 1));
|
memset(de, 0x7f, sizeof(de[0]) * (n + m + 1));
|
||||||
@@ -35,16 +36,32 @@ int main() {
|
|||||||
fri[sta].push_back({ti, m + i});
|
fri[sta].push_back({ti, m + i});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
memset(dline, 0x7f, sizeof dline);
|
||||||
|
for(int i = 1; i <= n; ++i) {
|
||||||
|
dig(m + i);
|
||||||
|
for(int j = 1; j <= n; ++j) {
|
||||||
|
dline[i][j] = de[m + j];
|
||||||
|
}
|
||||||
|
}
|
||||||
while(q--) {
|
while(q--) {
|
||||||
int x, y;
|
int x, y;
|
||||||
scanf("%d%d", &x, &y);
|
scanf("%d%d", &x, &y);
|
||||||
dig(x);
|
int ans = INT_MAX;
|
||||||
printf("%d\n", w[x] + w[y] + de[y]);
|
for(pair<int, int> i : fri[x]) {
|
||||||
|
for(pair<int, int> j : fri[y]) {
|
||||||
|
ans = min(ans, dline[i.second - m][j.second - m] + i.first + j.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// dig(x);
|
||||||
|
printf("%d\n", w[x] + w[y] + ans);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
1-15
|
||||||
g++ subway/subway.cpp -o subway/subway -std=c++14 -O2 -static -Wall && cp subway/subway ~ && chmod +x ~/subway && ~/subway
|
g++ subway/subway.cpp -o subway/subway -std=c++14 -O2 -static -Wall && cp subway/subway ~ && chmod +x ~/subway && ~/subway
|
||||||
|
|
||||||
500 条线路各视为图上的一个点,分别和地铁站连线
|
500 条线路各视为图上的一个点,分别和地铁站连线
|
||||||
|
|
||||||
|
考虑优化,注意到可以预处理维护两个地铁线路的最短距离,再枚举起点终点的线路选择
|
||||||
*/
|
*/
|
||||||
Reference in new issue
Block a user