Submission #983307

#TimeUsernameProblemLanguageResultExecution timeMemory
983307vjudge1사이버랜드 (APIO23_cyberland)C++17
20 / 100
26 ms7104 KiB
#include <vector>
#include <queue>
#include <limits>

using namespace std;

double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
    // Initialize the graph
    vector<vector<pair<int, int>>> graph(N);
    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 distances
    vector<double> dist(N, numeric_limits<double>::max());
    dist[0] = 0;  // Distance from your country to itself is 0
    
    // Priority queue to store {distance, country} pairs
    priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> pq;
    pq.push({0, 0});  // Start from your country
    
    while (!pq.empty()) {
        int u = pq.top().second;
        double d = pq.top().first;
        pq.pop();
        
        // Check if we have reached Cyberland
        if (u == H) return d;
        
        // Check if we have used up all divide-by-2 abilities
        int remaining_divide_by_2 = K;
        if (arr[u] == 2) remaining_divide_by_2--;
        
        for (auto& edge : graph[u]) {
            int v = edge.first;
            int cost = edge.second;
            double new_dist = d + cost;
            
            // Apply special ability of the country
            if (arr[v] == 0) new_dist = d;  // Passing time becomes 0
            else if (arr[v] == 2 && remaining_divide_by_2 > 0) {  // Divide-by-2 ability
                new_dist = d + cost / 2.0;
                remaining_divide_by_2--;
            }
            
            // Update the distance if the new path is shorter
            if (new_dist < dist[v]) {
                dist[v] = new_dist;
                pq.push({new_dist, v});
            }
        }
    }
    
    // If Cyberland is unreachable
    return -1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...