QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733910#7883. Takeout DeliveringXiaoYang3WA 118ms42768kbC++231.9kb2024-11-10 21:59:312024-11-10 21:59:32

Judging History

你现在查看的是最新测评结果

  • [2024-11-10 21:59:32]
  • 评测
  • 测评结果:WA
  • 用时:118ms
  • 内存:42768kb
  • [2024-11-10 21:59:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
const int N = 2e6 + 5;
const ll P = 1e9 + 7;
ll m, n, q, tot;
vector<pii> ve[N];
struct node {
    ll x, y, w;
} st[N];
void solve() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> st[i].x >> st[i].y >> st[i].w;
        ve[st[i].x].push_back({st[i].y, st[i].w});
        ve[st[i].y].push_back({st[i].x, st[i].w});
    }
    vector<ll> dis1(n + 2);
    vector<ll> dis2(n + 2);
    auto dij = [&](int now) -> void {
        vector<int> v(n + 2);
        vector<ll> dis(n + 2, 1e12);
        dis[now] = 0;
        priority_queue<pii, vector<pii>, greater<pii>> q;
        q.push({0, now});
        while (q.size()) {
            auto [d, x] = q.top();
            q.pop();
            if (v[x]) {
                continue;
            }
            v[x] = 1;
            for (auto [y, w] : ve[x]) {
                if (dis[y] > max(d, w)) {
                    dis[y] = min(dis[y], max(d, w));
                    q.push({dis[y], y});
                }
            }
        }
        if (now == 1) {
            for (int i = 1; i <= n; i++) {
                dis1[i] = dis[i];
            }
        } else {
            for (int i = 1; i <= n; i++) {
                dis2[i] = dis[i];
            }
        }
    };
    dij(1);
    dij(n);
    ll ans = 1e12;
    for (int i = 1; i <= m; i++) {
        auto [x, y, w] = st[i];
        // cout << dis1[x] << ' ' << dis2[y] << '\n';
        ll sum = w + dis1[x] + dis2[y];

        ans = min(ans, sum - min({w, dis1[x], dis2[y]}));
        sum = w + dis1[y] + dis2[x];
        ans = min(ans, sum - min({w, dis1[y], dis2[x]}));
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _ = 1;
    // cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3832kb

input:

4 6
1 2 2
1 3 4
1 4 7
2 3 1
2 4 3
3 4 9

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: -100
Wrong Answer
time: 118ms
memory: 42768kb

input:

300000 299999
80516 80517 597830404
110190 110191 82173886
218008 218009 954561262
250110 250111 942489774
66540 66541 156425292
34947 34948 239499776
273789 273790 453201232
84428 84429 439418398
98599 98600 326095035
55636 55637 355015760
158611 158612 684292473
43331 43332 43265001
171621 171622 ...

output:

1356916107

result:

wrong answer 1st numbers differ - expected: '1999991697', found: '1356916107'