World Robot Contest2025-2026Algorithm Application ThemeJunior Highwrc.hao.work
WRC
Contest Archive / Structured Dossiers青少年算法应用训练档案馆

把训练题、知识点、执行证据和最终解题档案统一归档成可直接浏览的竞赛资料库。

Archive30 Cases

四大文化赛道完整展开

AccessHTTPS

完整题面 / 题解 / 运行证据

No Rounded CornersTailwind FirstDossier Ready
03-execution/run-002/source-snapshot/main.cpp

main.cpp

站内文件视图直接读取仓库内容,Markdown 使用文档排版渲染,其余文本文件保持原始排版,方便校对训练证据链。

文件类型.cpp

10-cases/s3-jh-02-caravan-plan/03-execution/run-002/source-snapshot/main.cpp

#include <algorithm>
#include <iostream>
#include <limits>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, start, target, load;
    if (!(cin >> n >> m >> start >> target >> load)) {
        return 0;
    }
    vector<vector<tuple<int, int, int>>> graph(n + 1);
    for (int i = 0; i < m; ++i) {
        int u, v, dist, capacity, risk;
        cin >> u >> v >> dist >> capacity >> risk;
        if (capacity < load) {
            continue;
        }
        graph[u].push_back({v, dist, risk});
        graph[v].push_back({u, dist, risk});
    }

    const long long INF = numeric_limits<long long>::max() / 4;
    vector<long long> best_dist(n + 1, INF), best_risk(n + 1, INF);
    vector<int> prev(n + 1, -1);
    using State = tuple<long long, long long, int>;
    priority_queue<State, vector<State>, greater<State>> pq;
    best_dist[start] = 0;
    best_risk[start] = 0;
    pq.push({0, 0, start});

    while (!pq.empty()) {
        auto [cur_dist, cur_risk, node] = pq.top();
        pq.pop();
        if (cur_dist != best_dist[node] || cur_risk != best_risk[node]) {
            continue;
        }
        for (auto [nxt, dist, risk] : graph[node]) {
            long long nd = cur_dist + dist;
            long long nr = cur_risk + risk;
            if (nd < best_dist[nxt] || (nd == best_dist[nxt] && nr < best_risk[nxt])) {
                best_dist[nxt] = nd;
                best_risk[nxt] = nr;
                prev[nxt] = node;
                pq.push({nd, nr, nxt});
            }
        }
    }

    if (best_dist[target] == INF) {
        cout << "min_distance=-1\n";
        cout << "total_risk=-1\n";
        cout << "path=IMPOSSIBLE\n";
        return 0;
    }

    vector<int> path;
    for (int cur = target; cur != -1; cur = prev[cur]) {
        path.push_back(cur);
    }
    reverse(path.begin(), path.end());
    cout << "min_distance=" << best_dist[target] << "\n";
    cout << "total_risk=" << best_risk[target] << "\n";
    cout << "path=";
    for (size_t i = 0; i < path.size(); ++i) {
        if (i) {
            cout << "->";
        }
        cout << path[i];
    }
    cout << "\n";
    return 0;
}