00:19(160)

This commit is contained in:
Your Name committed 2026-11-01 00:19:14 +08:00
1 parent d09b9c8dc2
commit c641d85686
1 file changed
+7 -6
+7 -6
View File
@@ -3,15 +3,15 @@ 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];
int dline[505][505];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
long long de[500505];
long long dline[505][505];
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, 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();
pair<long long, int> u = pq.top();
pq.pop();
for(pair<int, int> v : fri[u.second]) {
if(de[v.second] > de[u.second] + v.first) {
@@ -43,17 +43,18 @@ int main() {
dline[i][j] = de[m + j];
}
}
// O(n log(m + n))
while(q--) {
int x, y;
scanf("%d%d", &x, &y);
int ans = INT_MAX;
long long ans = LLONG_MAX;
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);
printf("%lld\n", w[x] + w[y] + ans);
}
return 0;
}