Submission #884927

#TimeUsernameProblemLanguageResultExecution timeMemory
884927RaulAndrei01Cyberland (APIO23_cyberland)C++17
Compilation error
0 ms0 KiB
#include "cyberland.h"
#include <vector>
#include <queue>

using namespace std;
using ld = long double;
const int NMAX = 1e5;
const ld INF = 1e18;

vector<pair<int , ld> > adj[NMAX+1];
ld dist[60][NMAX+1];
vector<int> arr;
int n, m, k, h;
bool reach[NMAX+1];

void bfs ()
{
    queue<int> q;
    q.push(0);
    reach[0] = 1;
    while (q.size())
    {
        int nod = q.front();
        q.pop();
        for (auto &edg : adj[nod])
        {
            int to = edg.first
            if (!reach[to]) {
                reach[to] = 1;
                q.push(to);
            }
        }
    }
}

void dijktra (int layer)
{
    priority_queue<pair<ld, int> , vector<pair<ld, int> > , greater<pair<ld, int> > > q;
    
    for (int i = 0; i <n; i++)
    {
        if (reach[i] && arr[i] == 0 || i == 0) {
            q.push({0.0 , i});
            dist[layer][i] = 0;
        }
    }

    for (int c = 1; c < n; c++)
    {
        if (arr[c] == 2 && dist[layer-1][c] != INF)
        {
            q.push({dist[layer-1][c]/2 , c});
            dist[layer][c] = dist[layer-1][c]/2;
        }
    }

    while (q.size())
    {
        int nod = q.top().second;
        ld crtDist = q.top().first;
        q.pop();
        if (crtDist > dist[layer][nod]) continue;
        for (auto &edg : adj[nod])
        {
            int to = edg.first;
            ld cost = edg.second;
            if (dist[layer][to] > dist[layer][nod] + cost)
            {
                dist[layer][to] = dist[layer][nod] + cost;
                q.push({dist[layer][to] , to});
            }
        }
    }
}

double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> _arr) {
    
    n = N; m = M, k = K, h = H;
    for (int i = 0; i < m; i++)
    {
        adj[x[i]].push_back({y[i] , c[i]});
        adj[y[i]].push_back({x[i] , c[i]});
    }
    arr = _arr;
    bfs();

    for (int c = 0; c < n; c++)
    {
        dist[0][c] = INF;
    }
    
    for (int i = 1; i <= min(K , 59); i++)
    {
        for (int c = 0; c < n; c++)
        {
            dist[i][c] = INF;
        }
        dijktra(i);
    }

    for (int i = 0; i < n; i++)
    {
        adj[i].clear();
        reach[i] = 0;
    }

    return dist[min(K, 59)][h];
}

Compilation message (stderr)

cyberland.cpp: In function 'void bfs()':
cyberland.cpp:28:13: error: expected ',' or ';' before 'if'
   28 |             if (!reach[to]) {
      |             ^~
cyberland.cpp:27:17: warning: unused variable 'to' [-Wunused-variable]
   27 |             int to = edg.first
      |                 ^~
cyberland.cpp: In function 'void dijktra(int)':
cyberland.cpp:42:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   42 |         if (reach[i] && arr[i] == 0 || i == 0) {
      |             ~~~~~~~~~^~~~~~~~~~~~~~