diff --git a/subway/subway.cpp b/subway/subway.cpp index e7d7d6f..5c2e2dc 100644 --- a/subway/subway.cpp +++ b/subway/subway.cpp @@ -3,15 +3,15 @@ using namespace std; int c, n, m, d, q; // 25 500 5e5 20 1e5 int w[500005]; vector> fri[500505]; -int de[500505]; -int dline[505][505]; -priority_queue, vector>, greater>> pq; +long long de[500505]; +long long dline[505][505]; +priority_queue, vector>, greater>> 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 u = pq.top(); + pair u = pq.top(); pq.pop(); for(pair 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 i : fri[x]) { for(pair 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; }