제출 #1361395

#제출 시각아이디문제언어결과실행 시간메모리
1361395ramez-hammad사이버랜드 (APIO23_cyberland)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;
using ll=long long;
using ld=long double;

const ll INF=1e18;

#define pb push_back

vector<bool> reachable(N,false);
vector<vector<pair<int,ld>>> adj(N); 

void dfs(int n) {
    if (reachable[n]) return;
    reachable[n]=true;
    for (auto u : adj[n]) {
        auto [a,ignore,ignore]=u;
        dfs(a);
    }
}

double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
    priority_queue<tuple<ld,int,int>,vector<tuple<ld,int,int>>,greater<tuple<ld,int,int>>> q;
    dfs(0);
    for (int i=0;i<M;i++) {
        adj[x[i]].pb({y[i],(ld)c[i]});
        adj[y[i]].pb({x[i],(ld)c[i]});
    }
    vector<vector<ld>> distance(N+1,vector<ld>(K+1,(ld)INF));
    for (int i=0;i<N;i++) {
        if (arr[i]==0 and reachable[i]) {
            for (int j=0;j<=K;j++) distance[i][j]=0;
            q.push({0.0,i,0})
        } 
    }
    vector<vector<bool>> processed(N+1,vector<bool>(K+1));
    for (int i=0;i<=K;i++) distance[0][i]=0;
    q.push({0.0,0,0});
    while (!q.empty()) {
        auto [ignore,a,k]=q.top(); q.pop(); 
        if (a==H) continue;
        if (processed[a][k]) continue;
        processed[a][k]=true;
        K=min(K,30);
        for (auto u : adj[a]) {
            auto [b,w]=u;
            if (arr[b]==0) {
                if (distance[b][k]!=0) {
                    distance[b][k]=0;
                    q.push({distance[b][k],b,k});
                }
            } else if (arr[b]==2) {
                if (k+1<=K) {
                    if ((distance[a][k]+w)/2<distance[b][k+1]) {
                        distance[b][k+1]=(distance[a][k]+w)/2;
                        q.push({distance[b][k+1],b,k+1});
                    }
                } 
                if (distance[a][k]+w<distance[b][k]) {
                    distance[b][k]=distance[a][k]+w;
                    q.push({distance[b][k],b,k});
                }
            } else {
                if (distance[a][k]+w<distance[b][k]) {
                    distance[b][k]=distance[a][k]+w;
                    q.push({distance[b][k],b,k});
                }
            }
        }
    }
    reachable.clear();
    for (int i=0;i<N;i++) adj[i].clear();
    ld ans=(ld)INF;
    for (int i=0;i<=K;i++) ans=min(ans,distance[H][i]);
    ans=(ans==(ld)INF) ? -1 : ans;
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

cyberland.cpp:11:24: error: 'N' was not declared in this scope
   11 | vector<bool> reachable(N,false);
      |                        ^
cyberland.cpp:12:34: error: 'N' was not declared in this scope
   12 | vector<vector<pair<int,ld>>> adj(N);
      |                                  ^
cyberland.cpp: In function 'void dfs(int)':
cyberland.cpp:18:24: error: redeclaration of 'auto ignore'
   18 |         auto [a,ignore,ignore]=u;
      |                        ^~~~~~
cyberland.cpp:18:17: note: 'auto ignore' previously declared here
   18 |         auto [a,ignore,ignore]=u;
      |                 ^~~~~~
cyberland.cpp:19:13: error: use of 'a' before deduction of 'auto'
   19 |         dfs(a);
      |             ^
cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:34:30: error: expected ';' before '}' token
   34 |             q.push({0.0,i,0})
      |                              ^
      |                              ;
   35 |         }
      |         ~