QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691672#7883. Takeout DeliveringcbbdhzWA 81ms37548kbC++201.7kb2024-10-31 12:33:352024-10-31 12:33:37

Judging History

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

  • [2024-10-31 12:33:37]
  • 评测
  • 测评结果:WA
  • 用时:81ms
  • 内存:37548kb
  • [2024-10-31 12:33:35]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 300001;
const int M = 1000001;
int head[N];
int nxt[M << 1];
int to[M << 1];
int wei[M << 1];
int cnt = 1;
void ege(int a, int b, int c) {
    to[cnt] = b;
    wei[cnt] = c;
    nxt[cnt] = head[a];
    head[a] = cnt++;
}
int vis1[N], vis2[N];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    vector<array<int, 3>> edge;
    for (int i = 1; i <= m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        edge.push_back({a, b, c});
        ege(a, b, c);
        ege(b, a, c);
    }

    auto dijkstra = [&](int start, int *dist) {
        priority_queue<array<int, 2>, vector<array<int, 2>>, greater<>> que;
        fill(dist, dist + n + 1, LLONG_MAX);
        dist[start] = 0;
        que.push({0, start});
        
        while (!que.empty()) {
            auto [w, s] = que.top();
            que.pop();
            if (w > dist[s]) continue;
            for (int i = head[s]; i != 0; i = nxt[i]) {
                int nt = to[i];
                if (dist[s] + wei[i] < dist[nt]) {
                    dist[nt] = dist[s] + wei[i];
                    que.push({dist[nt], nt});
                }
            }
        }
    };

    // 运行双向 Dijkstra
    dijkstra(1, vis1);
    dijkstra(n, vis2);

    int ans = LLONG_MAX;
    for (auto [a, b, c] : edge) {
        int minPathThroughEdge = min(max(vis1[a], vis2[b]), max(vis1[b], vis2[a]));
        if (minPathThroughEdge <= c) {
            ans = min(ans, minPathThroughEdge + c);
        }
    }
    
    cout << ans << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11804kb

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: 81ms
memory: 37548kb

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:

9223372036854775807

result:

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