제출 #983089

#제출 시각아이디문제언어결과실행 시간메모리
983089vjudge1사이버랜드 (APIO23_cyberland)C++17
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>

using namespace std;

const int INF = numeric_limits<int>::max();

double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
    // Define a graph using adjacency list
    vector<vector<pair<int, int>>> graph(N);
    
    // Fill the graph with edges and costs
    for (int i = 0; i < M; ++i) {
        graph[x[i]].push_back({y[i], c[i]});
        graph[y[i]].push_back({x[i], c[i]});
    }
    
    // Initialize the distance array to infinity
    vector<int> dist(N, INF);
    
    // Priority queue to store vertices and their distances
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    
    // Push the starting node into the priority queue
    pq.push({0, 0});
    dist[0] = 0;
    
    while (!pq.empty()) {
        // Extract the vertex with the minimum distance
        int u = pq.top().second;
        int d = pq.top().first;
        pq.pop();
        
        // If the extracted vertex is Cyberland, return the distance
        if (u == H) return dist[u];
        
        // Iterate through all neighboring vertices of u
        for (auto& neighbor : graph[u]) {
            int v = neighbor.first;
            int weight = neighbor.second;
            int new_dist = dist[u] + weight;
            
            // Apply special abilities if necessary
            if (arr[v] == 2 && K > 0) {
                new_dist /= 2;
                K--;
            } else if (arr[v] == 0) {
                new_dist = 0;
            }
            
            // Update the distance if a shorter path is found
            if (new_dist < dist[v]) {
                dist[v] = new_dist;
                pq.push({dist[v], v});
            }
        }
    }
    
    // If Cyberland is not reachable, return -1
    return -1;
}

int main() {
    // Example usage
    cout << solve(3, 2, 30, 2, {1, 2}, {2, 0}, {12, 4}, {1, 2, 1}) << endl; // Output: 4
    cout << solve(4, 4, 30, 3, {0, 0, 1, 2}, {1, 2, 3, 3}, {5, 4, 2, 4}, {1, 0, 2, 1}) << endl; // Output: 2
    return 0;
}

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

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:13: warning: unused variable 'd' [-Wunused-variable]
   34 |         int d = pq.top().first;
      |             ^
/usr/bin/ld: /tmp/ccvp0cbY.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccFjUcNY.o:cyberland.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status