Submission #981872

#TimeUsernameProblemLanguageResultExecution timeMemory
981872MaaxleCyberland (APIO23_cyberland)C++17
Compilation error
0 ms0 KiB
#include "cyberland.h"
#include <bits/stdc++.h>

#define range(it, a, b) for (ll it = a; it < b; it++)
#define all(x) begin(x), end(x)
#define ll long long
#define ull unsigned long long
#define INF64 ((ll) 1 << 62)
#define INF32 (1 << 30)
#define mset multiset
#define uset unordered_set
#define umap unordered_map 
#define pqueue priority_queue 
#define ptr(A) shared_ptr<A>

using namespace std;

struct TPos {
    int i, w;
};
bool operator < (const TPos& a, const TPos& b) {
    return a.w > b.w;
}

vector<vector<TPos>> adj;
vector<int> a;
vector<double> memo;

// void dijkstra() {
//     pqueue<TPos> pq;
//     pq.push({0, 0});

//     TPos t, nt;
//     while (!pq.empty()) {
//         t = pq.top();
//         pq.pop();

//         if (memo[t.i] < t.w)
//             continue;
//         memo[t.i] = t.w;

//         for (TPos& it : adj[t.i]) {
//             nt = {it.i, (a[it.i] == 0 ? 0 : memo[t.i] + it.w)};
//             if (memo[it.i] > nt.w)
//                 pq.push(nt);
//         }
//     }
// }

void dfs(int i, int& H, double w) {
    memo[i] = (a[i] == 0 ? 0 : w);
    if (i == H) return;
    
    for (TPos& it : adj[i]) {
        if (memo[it.i] == INF64) 
            dfs(it.i, memo[i]+it.w);
    }
}

double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
    adj.clear();
    adj.resize(N);

    memo.clear();
    memo.resize(N, INF64);

    a = arr;

    range(i, 0, M) {
        adj[x[i]].push_back({y[i], c[i]});
        adj[y[i]].push_back({x[i], c[i]});
    }

    dfs(0, 0);
    return (memo[H] == INF64 ? -1 : memo[H]);
}

Compilation message (stderr)

cyberland.cpp: In function 'void dfs(int, int&, double)':
cyberland.cpp:56:30: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   56 |             dfs(it.i, memo[i]+it.w);
cyberland.cpp:50:22: note: in passing argument 2 of 'void dfs(int, int&, double)'
   50 | void dfs(int i, int& H, double w) {
      |                 ~~~~~^
cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:74:12: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   74 |     dfs(0, 0);
      |            ^
cyberland.cpp:50:22: note: in passing argument 2 of 'void dfs(int, int&, double)'
   50 | void dfs(int i, int& H, double w) {
      |                 ~~~~~^