QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#273754#7883. Takeout Deliveringucup-team2000#WA 419ms58300kbC++202.0kb2023-12-03 03:52:472023-12-03 03:52:49

Judging History

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

  • [2023-12-03 03:52:49]
  • 评测
  • 测评结果:WA
  • 用时:419ms
  • 内存:58300kb
  • [2023-12-03 03:52:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

class DSU {
    public:
        vector<int> id;
        DSU(int n){
            id.resize(n);
            for (int i = 0; i < n; ++i) id[i] = i;
        }
        int find(int u) {
            if (id[u] == u) return u;
            return id[u] = find(id[u]);
        }

        void unionThese(int u, int v) {
            int idU = find(u), idV = find(v);
            id[idU] = idV;
        }
};

int main(){
    int n, m; cin >> n >> m;
    vector<vector<pair<int, int>>> adj(n + 1);
    vector<vector<int>> edges(m);
    for (int i = 0; i < m; ++i) {
        int u, v, w; cin >> u >> v >> w;
        adj[u].push_back({v,w});
        adj[v].push_back({u,w});
        edges[i] = {w, u, v};
    }
    sort(edges.begin(), edges.end());
    DSU uf = *(new DSU(n + 1));
    vector<vector<pair<int, int>>> res(n + 1);
    for (int i = 0; i < edges.size(); ++i) {
        vector<int> edge = edges[i];
        int u = edge[1], v = edge[2], w = edge[0];
        if (uf.find(u) != uf.find(v)) {
            res[u].push_back({v, w});
            res[v].push_back({u, w});
            uf.unionThese(u, v);
        }
    }
    vector<int> vis(n + 1); vector<pair<int, int>> ans(n + 1);
    for (int i = 0; i < n + 1; ++i) ans[i] = {-1, -1};
    queue<int> q; q.push(1); vis[1] = 1;
    while (!q.empty()) {
        int front = q.front(); q.pop();
        for (auto i : res[front]) {
            if (i.second >= ans[front].first) {
                ans[i.first].second = ans[front].first;
                ans[i.first].first = i.second;
            } else if (i.second > ans[front].second) {
                ans[i.first].first = ans[front].first;
                ans[i.first].second = i.second;
            }
            if (!vis[i.first]) {
                q.push(i.first);
                vis[i.first] = 1;
            }
        }
    }
    cout << ans[n].first + max(0, ans[n].second);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3508kb

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: 419ms
memory: 58300kb

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:

1440744755

result:

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