UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213347#2058. 小游戏KXGCompile Error//C++111.4kb2024-11-11 19:08:242024-11-11 23:01:33

answer

#include <cstdio>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;
struct node {
    int d, u, hp;
    node(int d = 0, int u = 0, int hp = 0) : d(d), u(u), hp(hp) {}
};
bool operator < (node a, node b) {
    return a.d > b.d;
}
vector<pair<int, int> > G[30010];
unordered_map<int, int> dis[30010];
queue<node> pq;
int n, m, k, x, y, z, a[30010];
void dijkstra() {
    pq.emplace(0, 1, k);
    dis[1][k] = 0;
    while (!pq.empty()) {
        node t = pq.front();
        pq.pop();
        // printf("%d %d %d\n", t.u, t.d, t.hp);
        int nowdis = dis[t.u][t.hp];
        t.hp = min(k, t.hp + a[t.u]);
        for (auto [v, w] : G[t.u]) {
            if (t.hp >= w) {
                if (!dis[v].count(t.hp - w)) {
                    dis[v][t.hp - w] = nowdis + 1;
                    pq.emplace(nowdis + 1, v, t.hp - w);
                }
            }
        }
    }
}
int main() {
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= m; i++) {
        scanf("%d%d%d", &x, &y, &z);
        G[x].push_back({y, z});
        G[y].push_back({x, z});
    }
    dijkstra();
    int ans = 1e9;
    for (auto d : dis[n]) {
        ans = min(ans, d.second);
    }
    if (ans == 1e9) ans = -1;
    printf("%d\n", ans);
    return 0;
}

详细

answer.code: In function 'void dijkstra()':
answer.code:28:19: error: expected unqualified-id before '[' token
         for (auto [v, w] : G[t.u]) {\x0d
                   ^
answer.code:28:19: error: expected ';' before '[' token
answer.code:28:20: error: 'v' was not declared in this scope
         for (auto [v, w] : G[t.u]) {\x0d
                    ^
answer.code:28:23: error: 'w' was not declared in this scope
         for (auto [v, w] : G[t.u]) {\x0d
                       ^
answer.code: In lambda fun...